我正在使用 TabLayout
和 ViewPager
来显示我的标签名称,如下所示。
但是正如您所看到的,我的标题覆盖了我的标签。我希望我的选项卡靠近屏幕顶部,如下所示。
这是我的view_pager.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="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="stellar.kade_c.com.MainActivity">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
如何实现?
最佳答案
将 app:tabMode="fixed"
更改为 app:tabMode="scrollable"
已修复
Fixed tabs display all tabs concurrently and are best used with content that benefits from quick pivots between tabs. The maximum number of tabs is limited by the view’s width. Fixed tabs have equal width, based on the widest tab label.
可滚动
Scrollable tabs display a subset of tabs at any given moment, and can contain longer tablabels and a larger number of tabs. They are best used for browsing contexts in touch interfaces when users don’t need to directly compare the tab labels.
关于android - 更改 TabLayout 选项卡位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41373005/