Android中tablayout怎么自定义布局
要自定义TabLayout的布局,可以通过实现自定义的TabLayout.TabLayout中的Tab的自定义布局。
首先,在xml文件中定义自定义的Tab布局,例如:
<LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical"><ImageViewandroid:id="@+id/tab_icon"android:layout_width="wrap_content"android:layout_height="wrap_content"/><TextViewandroid:id="@+id/tab_text"android:layout_width="wrap_content"android:layout_height="wrap_content"/></LinearLayout>
然后,在代码中创建自定义的TabLayout.Tab,并设置自定义的布局:
TabLayout.Tab tab1 = tabLayout.newTab();View customTab1 = LayoutInflater.from(this).inflate(R.layout.custom_tab_layout, null);ImageView tabIcon1 = customTab1.findViewById(R.id.tab_icon);TextView tabText1 = customTab1.findViewById(R.id.tab_text);tabIcon1.setImageResource(R.drawable.tab_icon);tabText1.setText("Tab 1");tab1.setCustomView(customTab1);tabLayout.addTab(tab1);
这样就可以实现自定义TabLayout的布局。在创建Tab的时候,可以根据需要设置不同的自定义布局。
下一篇:c语言清空数组元素的方法是什么
android
输入法切换键是哪个键?输入法切
冬月是哪一个月?冬月是什么意思
个人所得税退税金额怎么算出来的
输入法全角和半角有什么区别?输
a4纸尺寸是多少厘米?a4纸的由来
个人所得税扣除标准?个人所得税
输入法哪个好用?输入法介绍
卡拉OK是哪个国家发明的?卡拉OK
mikutools原神网页版入口链接?m
关机特别慢什么原因?电脑和手机