【问题标题】:How to show tab indicator at top of Tabs如何在选项卡顶部显示选项卡指示器
【发布时间】:2015-09-17 15:09:30
【问题描述】:

我关注了this tutorial。我做了简单的更改,在屏幕底部显示 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 显示在屏幕底部运行良好,现在我想在选项卡顶部而不是底部显示 TabIndicator。 使用自定义布局,我们可以按照教程中的说明进行操作,但是是否有任何 xml 属性会在顶部显示 TabIndicator

【问题讨论】:

  • 输入你的xml代码。谢谢
  • @Fakher 我已经发布了 xml
  • @Nilesh 你做到了吗?我还想在顶部显示标签指示器。
  • @NiteshKhatri 不是默认情况下,因为现在我已经为此做了自定义布局
  • 请参考here.的解决方案

标签: java android android-support-library androiddesignsupport


【解决方案1】:

将此行添加到 XML 中的 TabLayout

app:tabIndicatorGravity="top"

【讨论】:

    【解决方案2】:

    这对我有用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多