android - 更改 TabLayout 选项卡位置

标签 android android-viewpager android-tablayout

我正在使用 TabLayoutViewPager 来显示我的标签名称,如下所示。

enter image description here

但是正如您所看到的,我的标题覆盖了我的标签。我希望我的选项卡靠近屏幕顶部,如下所示。

enter image description here

这是我的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/

相关文章:

java - 如何在 AutocompleteSupportFragment 上设置 [ENTER/SEARCH/ETC...] 键触发器

android - 带有 fragment 的 ViewPager 和 FragmentPagerAdapter(不支持库)

java - setOnPageChangeListener 不调用 onPageSelected

android - 使用 TabItem 时如何将 TabLayout 与 ViewPager 同步

android-fragments - 使用选项卡式片段单击另一个 recyclerview 片段的特定项目时加载一个 recyclerview 片段?

android - 带有选项卡 fragment 的 fragment 堆栈

android - 为什么我在 android 7 上收到多个 FCM 通知

android - Android应用程序的更新

android - 使用带有 addValueEventListener 的查询

android - 未选中选项卡下划线的 TabLayout 颜色