繁体   English   中英

如何在选项卡顶部显示选项卡指示器

[英]How to show tab indicator at top of Tabs

我按照本教程 我做了一个简单的更改,在屏幕底部显示TabLayout

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager_landing"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:background="@android:color/white" />

    <android.support.design.widget.TabLayout
        android:id="@+id/sliding_tabs_landing"
        style="@style/MyCustomTabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed" />

</LinearLayout>

在此输入图像描述

问题:-

TabIndicator显示在屏幕底部工作正常,现在我想在Tabs的顶部而不是底部显示TabIndicator 使用自定义布局我们可以像教程中提到的那样做,但是有没有任何xml属性会在顶部显示TabIndicator

这对我有用:

LinearLayout tabs = ((LinearLayout) tabLayout.getChildAt(0));

for (int position = 0; position < tabs.getChildCount(); position++) {
    LinearLayout item = ((LinearLayout) tabs.getChildAt(position));
    item.setRotationX(180);
}

将此行添加到XML中的TabLayout

app:tabIndicatorGravity="top"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM