Hy everyone! :)Tabitem在android studio中绑定
我需要在选项卡式活动(或片段)tabitem自定义布局。
第一 - >我定义这个布局为TabItem的: tab_item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:id="@+id/tab_item_root_linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tab_item_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Wink from"/>
<TextView
android:id="@+id/tab_item_number_text_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:text="1"/>
</LinearLayout>
</layout>
所需Databinding布局标签。
二线>限定的tablayout(在片段但我没有附此): fragment_surf_base.xml(这是与tablayout片段)
<android.support.design.widget.TabLayout
android:id="@+id/surf_tab_layout"
android:layout_width="368dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.TabItem
android:id="@+id/tabItem1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/tab_item_layout" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/tab_item_layout" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/tab_item_layout" />
</android.support.design.widget.TabLayout>
,我需要的标签项(在与这些代码Java文件绑定):
Initilazie我绑定类的实例:
binding = DataBindingUtil.inflate(inflater,R.layout.fragment_surf_base, container, false);
现在,这个绑定实例在使用(return null !!但为什么 ? ):
binding.tabItem1;这是空的,但我不知道为什么?
,我需要的TabItem的版面项目(tab_item_name_text_view和tab_item_number_text_view)与tab_item_layout绑定类的实例由binding.tabItem1.bindingClassInstanceReturnedItem < < - 但我没有:\
任何想法对于这个问题? :\ 再见! :)
(对不起我的英文不好)
我知道这一点。但我需要tabitem布局项目绑定。 示例:binding.tabitem1.nameTextView.setText(“asdad”)。 编辑: 而binding.tabItem1为空 但我使用tablayout.getTabAt(0)这不是null,但这是一个tablayout.tab,我不知道投射到tabitem或其他。 –