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

做外单都有什么网站西安seo优化排名

做外单都有什么网站,西安seo优化排名,网站建设公司起名,商务网页设计与制作干嘛的高版本的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.shuangfujiaoyu.com/news/31534.html

相关文章:

  • 哪个素材网站做美工最好如何制作自己的网站教程
  • 那个网站专门做二手衣服的电子商务营销的概念
  • 工业设计网站 知乎怎么搭建属于自己的网站
  • 做网站 如何注册公司精准营销的案例
  • 建造网站需要什么网上销售平台有哪些
  • 卖水果做哪个网站好南昌做seo的公司有哪些
  • 宿迁百度排名优化seo公司
  • 做石膏选图形的网站seo视频教程我要自学网
  • html5 经典网站电商
  • 建设网站的公司哪家好互联网平台公司有哪些
  • 如何做1个手机网站深圳推广服务
  • 各类网站建设广州百度快速优化排名
  • 网站流量刷指数型基金
  • 购物网站开发seo诊断专家
  • 大部分网站是国内虚拟主机和国外虚拟主机在运营中seo是什么意思
  • 网站建设技术支持祥云平台网络推广学校
  • wordpress模版snsseo营销培训咨询
  • 网站建设多少钱?长沙百家号seo
  • 兰州建设网站公司时事新闻最新消息
  • 衡阳网站建设icp备免费网站制作成品
  • 如何让自己做的网页有网站石家庄seo外包公司
  • 厦门市建设局网站文件太原seo外包服务
  • 做网站基本费用大概需要多少东莞百度推广排名
  • 做外贸怎么看外国网站seo推广公司哪家好
  • 潜江网站搭建如何制作一个个人网站
  • 和镜像网站做友链百度浏览器网址链接
  • 南京房产网站建设搜索引擎优化的技巧有哪些
  • wordpress买域名智能优化大师下载
  • 武汉网站排名推广公司网站设计报价
  • 网站开发语言在线检测网站运营推广