简体   繁体   English

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

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

I followed this tutorial . 我按照本教程 I have made simple change that shows TabLayout at bottom of screen. 我做了一个简单的更改,在屏幕底部显示TabLayout

activity_main.xml 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>

在此输入图像描述

Problem:- 问题:-

TabIndicator is showing at bottom of screen working well,Now I want to show that TabIndicator at Top of Tabs rather than bottom. TabIndicator显示在屏幕底部工作正常,现在我想在Tabs的顶部而不是底部显示TabIndicator Using custom layout we can do that as mentioned in tutorial but is there any xml attribute that will show TabIndicator at top ? 使用自定义布局我们可以像教程中提到的那样做,但是有没有任何xml属性会在顶部显示TabIndicator

This worked for me: 这对我有用:

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