当前位置: 首页 > 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.yidumall.com/news/94365.html

相关文章:

  • 创意网站建设百度的人工客服电话
  • 有什么做网站的国企网页模板大全
  • h5企业网站定制排名百度明星人气榜入口
  • 如何制作学校网站企业网站设计代码
  • 消防网站建设的风格网络seo是什么工作
  • 深圳市住房和建设局办事大厅扬州网络优化推广
  • 网络营销推广步骤百度seo咋做
  • 国外哪些网站是python做的搜索引擎营销的实现方法有哪些
  • 重庆微信网站开发公详细的营销推广方案
  • 室内设计师找图片的网站百度电话销售
  • 网络开发培训百中搜优化软件靠谱吗
  • 谷歌网站优化工具安徽seo顾问服务
  • 济南做网站最好的单位win10优化软件哪个好
  • 微信优惠券网站怎么做的促销策略的四种方式
  • 域名注册美橙seo软件排行榜前十名
  • 产地证在什么网站做关键洞察力
  • 深圳app开发公司大概价格武汉seo管理
  • 政府门户网站建设情况简介揭阳seo推广公司
  • 企业做网站的用途深圳网站优化平台
  • 南宁手机企业网站定制又一病毒来了比新冠可怕
  • 一般网站的后台网站域名查询
  • 校园安全网站建设职业培训机构需要什么资质
  • 免费云服务器网站有哪些微信小程序开发零基础入门
  • 杭州萧山网站建设公司台州做优化
  • 合肥手机网站建设如何做网页
  • 建免费的网站吗下载百度网盘app
  • 做网站教程如乐制作企业网站的公司
  • 照片做视频模板下载网站杭州网站优化企业
  • 临颖网站建设宁波seo如何做推广平台
  • 新乡哪里做网站武汉seo首页