Android TabLayout.选项卡未填充
我将Android TabLayout.选项卡未填充,android,android-layout,android-viewpager,android-tablayout,Android,Android Layout,Android Viewpager,Android Tablayout,我将TabLayout与PageViewer一起使用,但选项卡并没有填满整个TabLayout 在xml中,设置GRAVITY\u FILL和MODE\u FIXED是不够的,但是设置 android.support.design:tabMaxWidth=0dp 这将解决问题 但是,由于TabLayout.setupWithViewPager(ViewPager)将覆盖TabLayout的TabItems,因此我正在以编程方式设置选项卡 现在TabLayout.Tab的显示不均匀。。。。有人能
TabLayout
与PageViewer
一起使用,但选项卡并没有填满整个TabLayout
在xml中,设置GRAVITY\u FILL
和MODE\u FIXED
是不够的,但是设置
android.support.design:tabMaxWidth=0dp
这将解决问题
但是,由于TabLayout.setupWithViewPager(ViewPager)
将覆盖TabLayout
的TabItem
s,因此我正在以编程方式设置选项卡
现在TabLayout.Tab的显示不均匀。。。。有人能帮忙吗
TabLayout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:showIn="@layout/activity_main">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
app:tabGravity="fill"
app:tabIndicatorColor="@color/tab_selected_text_color"
app:tabMode="fixed"
app:tabMaxWidth="0dp"> <!--this makes tabitem text filled evenly-->
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_list_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tab_layout"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager> <!--not overlapping with appbar-->
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:elevation="@dimen/shadow"
android:tint="@android:color/background_light"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
app:srcCompat="@android:drawable/ic_input_add"
tools:ignore="UnusedAttribute"
tools:targetApi="lollipop" />
</RelativeLayout>
目前:
更新
这个问题发生在今天早些时候,我在谷歌上搜索了这么多,但没有得到修复。
直到现在
更改为:
Tab t=TabLayout.getTab代码>t.setCustomView(v)代码>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
app:tabGravity="fill"
app:tabIndicatorColor="@color/tab_selected_text_color"
app:tabMode="fixed"
app:tabMaxWidth="0dp"> <!--this makes tabitem text filled evenly-->
<!--TabItem are just view holders and not actually added to TabLayout-->
<!--overridden by viewPagerAdapter.getPageTitle()-->
<android.support.design.widget.TabItem
android:id="@+id/tabItemList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/tab_color_selector"/>
<android.support.design.widget.TabItem
android:id="@+id/tabItemMap"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/tab_color_selector" />
</android.support.design.widget.TabLayout>
这为我解决了问题。谢谢大家 我认为您需要将整个xml in tablayout放在带有垂直方向的线性布局中,因此我认为您已经解决了这个问题。“那你的问题是什么?”ReazMurshed说问题没有解决。使用上面的代码,选项卡不会被填充….
android.support.design:tabMaxWidth=0dp
您说过设置此选项后问题已得到解决。@VinayJaju doneI我认为您需要将tablayout中的整个xml以垂直方向线性布局,因此我认为您已经解决了问题。“那你的问题是什么?”ReazMurshed说问题没有解决。使用上面的代码,选项卡没有填充….android.support.design:tabMaxWidth=0dp
您说过设置此选项后问题已得到解决。@VinayJaju完成
compile "com.android.support:appcompat-v7:26.1.0"
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
app:tabGravity="fill"
app:tabIndicatorColor="@color/tab_selected_text_color"
app:tabMode="fixed"
app:tabMaxWidth="0dp"> <!--this makes tabitem text filled evenly-->
<!--TabItem are just view holders and not actually added to TabLayout-->
<!--overridden by viewPagerAdapter.getPageTitle()-->
<android.support.design.widget.TabItem
android:id="@+id/tabItemList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/tab_color_selector"/>
<android.support.design.widget.TabItem
android:id="@+id/tabItemMap"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/tab_color_selector" />
</android.support.design.widget.TabLayout>
Tab tab = tabLayout.getTabAt(i);
tab.setCustomView(tabCustomView);