Android 如何使表格布局占据整个屏幕宽度?
Android 如何使表格布局占据整个屏幕宽度?,android,android-layout,android-styles,android-tablayout,Android,Android Layout,Android Styles,Android Tablayout,TabLayout上的我的选项卡占据了屏幕的中心,即使在按照添加tabMaxWidth=“0dp”后,也不会填满整个宽度 也就是说,我希望通过选项卡扩展以填充屏幕,如下所示: 但我得到的是: 我的XML如下所示: <android.support.design.widget.TabLayout android:id="@+id/tl_contact_type" style="@style/tabWidgetLayout"
TabLayout
上的我的选项卡占据了屏幕的中心,即使在按照添加tabMaxWidth=“0dp”
后,也不会填满整个宽度
也就是说,我希望通过选项卡扩展以填充屏幕,如下所示:
但我得到的是:
我的XML如下所示:
<android.support.design.widget.TabLayout
android:id="@+id/tl_contact_type"
style="@style/tabWidgetLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"/>
非常感谢您为解决此问题提供的任何帮助。
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabMaxWidth="0dp"
app:tabGravity="fill"/>
告诉我这是否解决了你的问题
很乐意提供帮助。值得一看@style/tabWidgetLayout及其父布局的填充和边距值 试试下面的代码片段
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed" />
用这个替换你的代码。我认为问题在于你没有扩展
android:Widget
尝试将此添加到您的style.xml
:
<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
<item name="tabBackground">@drawable/tab_background</item>
<item name="tabIndicatorColor">@color/colorAccent</item>
<item name="tabIndicatorHeight">2dp</item>
</style>
@可绘制/制表符背景
@颜色/颜色重音
2dp
然后在布局中:
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
style="@style/Base.Widget.Design.TabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed" />
编辑:
很久以前,我在另一个问题(我不记得了)中发现了这一点,它对我很有用更改
android:layout\u width=“match\u parent”
或设置此属性的自定义大小
<android.support.v4.view.ViewPager
android:id="@+id/viewTab"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_editor_absoluteX="8dp"
app:layout_editor_absoluteY="8dp">
</android.support.v4.view.ViewPager>
从屏幕截图上看,您似乎正在平板电脑上运行它。在普通的安卓系统上试一试phone@VivekMishra谢谢你的建议。然而,这些都是库存图片,我添加它们只是为了强调我的布局是如何呈现的。我一直在尝试普通的安卓手机(HTC),但标签并没有占据整个宽度。删除maxWidth
仍然保持不变?你能在问题中发布tabWidgetLayout
你的风格吗???@Vucko是的。还是一样。谢谢你的建议!但这并没有解决问题。这是我最初的布局。根据我附加在问题上的链接,我添加了tabMaxWidth
参数。我重新访问了使用选项卡布局的应用程序。看起来这是选项卡的默认行为。在我的手机上,标签在纵向上占据整个宽度,但在横向上不占。你试过在sw600上运行吗?
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
style="@style/Base.Widget.Design.TabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="@+id/viewTab"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_editor_absoluteX="8dp"
app:layout_editor_absoluteY="8dp">
</android.support.v4.view.ViewPager>