簡體   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