当前位置: 首页 > news >正文

网站的百度地图怎么做查询网

网站的百度地图怎么做,查询网,自己做的网站容易被黑吗,什么网站可以做免费广告高版本的gradle不再支持 kotlin-android-extensions插件,因此view的绑定方式也有所改变。 1.启用视图绑定 android {...viewBinding {enabled true}} 如果想在生成绑定类时忽略某个布局文件,请将 tools:viewBindingIgnore"true" 属性添加到…

高版本的gradle不再支持 kotlin-android-extensions插件,因此view的绑定方式也有所改变。

1.启用视图绑定

android {...viewBinding {enabled = true}}

如果想在生成绑定类时忽略某个布局文件,请将 tools:viewBindingIgnore="true" 属性添加到相应布局文件的根视图中:

<LinearLayout...tools:viewBindingIgnore="true" >...
</LinearLayout>

2.在 Activity 中使用视图绑定

如需设置绑定类的实例以供 Activity 使用,请在 Activity 的 onCreate() 方法中执行以下步骤:

  1. 调用生成的绑定类中包含的静态 inflate() 方法。此操作会创建该绑定类的实例以供 Activity 使用。
  2. 通过调用 getRoot() 方法或使用 Kotlin 属性语法获取对根视图的引用。
  3. 将根视图传递到 setContentView(),使其成为屏幕上的活动视图。
 private lateinit var binding: ResultProfileBindingoverride fun onCreate(savedInstanceState: Bundle) {super.onCreate(savedInstanceState)binding = ResultProfileBinding.inflate(layoutInflater)val view = binding.rootsetContentView(view)}

3.在 Fragment中使用视图绑定

如需设置绑定类的实例以供 Fragment 使用,请在 Fragment 的 onCreateView() 方法中执行以下步骤:

  1. 调用生成的绑定类中包含的静态 inflate() 方法。此操作会创建该绑定类的实例以供 Fragment 使用。
  2. 通过调用 getRoot() 方法或使用 Kotlin 属性语法获取对根视图的引用。
  3. 从 onCreateView() 方法返回根视图,使其成为屏幕上的活动视图。
    private var _binding: ResultProfileBinding? = nullprivate val binding get() = _binding!!override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?): View? {_binding = ResultProfileBinding.inflate(inflater, container, false)return binding.root}override fun onDestroyView() {super.onDestroyView()_binding = null}

4.自定义Dialog中使用

public class MyDialog extends Dialog {protected View mView;protected DialogBottomBinding mBinding;public MyDialog(@NonNull Context context, @StyleRes int themeResId) {super(context, themeResId);//原来的写法// mView = View.inflate(getContext(), getLayoutId(), null);//使用ViewBinding的写法mBinding = DialogBottomBinding.inflate(getLayoutInflater());mView = mBinding.getRoot();setContentView(mView);}
}

5.在自定义View中使用

// 自定义view
public class MyLinearLayout extends LinearLayout {public MyLinearLayout(Context context) {this(context, null);}public MyLinearLayout(Context context, @Nullable AttributeSet attrs) {this(context, attrs, 0);}public MyLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);// 正常添加布局(亲测有效)ViewMyLayoutBinding binding = LibPlateformLayoutBinding.inflate(LayoutInflater.from(getContext()), this, true);// 方法二:// val root = View.inflate(context, R.layout.widget_core, this)// binding = WidgetCoreBinding.bind(root)// 针对根标签为mergeViewMyLayoutMergeBinding binding = ViewMyLayoutMergeBinding.inflate(LayoutInflater.from(getContext()), this);}}

6.在RecyclerView的Adapter中使用

class StudentAdapter(private val context: Context,private val list: List<AddressInfo>) : RecyclerView.Adapter<ItemViewHolder>() {override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {val studentBinding = ItemAddressBinding.inflate(LayoutInflater.from(context), parent, false)return ItemViewHolder(studentBinding)}@SuppressLint("SetTextI18n")override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {holder.itemBinding.tvName.text = "姓名:" + list[position].name}override fun getItemCount(): Int {return list.size}inner class ItemViewHolder(var itemBinding: ItemAddressBinding) : RecyclerView.ViewHolder(itemBinding.root)
}

以上是各场景使用viewBinding的方式,基本可以满足大家的开发需求,如有其他场景的可以在评论区留言讨论。

http://www.ds6.com.cn/news/54078.html

相关文章:

  • 做网站推广有用吗郑志平爱站网创始人
  • 网站开发3687474企鹅长沙弧度seo
  • 减肥网站开发目的百度seo新算法
  • 做网站建设优化的公司南宁百度推广代理公司
  • 网站主题定位成人短期技能培训
  • 网站静态和动态那个好google移动服务应用优化
  • 快速网站建设费用百度广告投放价格
  • 崇卅市网站建设百度一下你就知道官页
  • 做性的网站有哪些泽成seo网站排名
  • 美丽说网站案例分析谷歌外链代发
  • 易签到网站开发设计广东seo网站优化公司
  • 建立网站seo 资料包怎么获得
  • cms系统和网站后台系统seo收录查询工具
  • 台湾做电商网站百度服务热线
  • wordpress 主题库冯耀宗seo博客
  • 网站脑图怎么做sem和seo的关系
  • h5网站开发实例教程新闻今日头条最新消息
  • 加密网站站长之家爱站网
  • 中企动力网站怎么样地推一手项目平台
  • 杭州企业网站建设电商运营转行后悔了
  • iis网站日志什么是seo网站优化
  • 建筑公司网站应该则么做googleseo推广
  • 建设一个网站的费用上海seo公司
  • wordpress页面禁止复制保存江苏关键词推广seo
  • 大型企业网络搭建长沙seo关键词排名优化
  • 交互型网站网站页面禁止访问
  • 阜新市建设学校官方网站大数据精准营销系统
  • 个人做网站如何赚钱如何推广一款app
  • 长沙企业建站方案seo教学
  • 北京随喜设计网站青岛官网seo公司