【问题标题】:How to show tab indicator on top of tab in android?如何在 android 的选项卡顶部显示选项卡指示器?
【发布时间】:2018-01-15 04:51:01
【问题描述】:

我有一个应用程序,我在其中添加了 TabLayout 和三个选项卡。我想从下到上显示选项卡指示器,但问题是当我从下到上显示指示器时选项卡图标也会旋转。如何解决此问题?

    mTabLayout.getTabAt(0).setCustomView(view);
    mTabLayout.getTabAt(1).setIcon(tabIcons[1]);
    mTabLayout.getTabAt(2).setIcon(tabIcons[2]);
    mTabLayout.setRotationX(180);

【问题讨论】:

  • 能分享一下截图吗??
  • 当然............
  • 请查看屏幕截图
  • 所以你想在屏幕左侧垂直附加标签布局。 . .对???
  • 当我将指示器更改为选项卡的顶部图标时也会旋转

标签: android tabs


【解决方案1】:

我之前的申请也有类似的要求

请试试下面的代码,它对我很有效

//First rotate the tab layout
     tabOrderType.setRotationX(180);

//Find all childs for tablayout
            for (int i = 0; i <tabOrderType.getChildCount() ; i++) {
                    LinearLayout linearList = ((LinearLayout)tabOrderType.getChildAt(i));

                    for(int position = 0;position<linearList.getChildCount();position++) {
//One by one again rotate layout for text and icons
                        LinearLayout item=((LinearLayout) linearList.getChildAt(position));
                        item.setBackground(getResources().getDrawable(R.drawable.custom_button_border));
                        item.setRotationX(180);
                    }
                }

这在我的应用程序中运行良好,直到现在还没有产生任何问题。另一种方法是您需要制作自定义选项卡来管理它。

希望这对您有所帮助...如果有任何问题请问我...

【讨论】:

    【解决方案2】:

    在你的 TabLayout XML 中添加这个

    app:tabIndicatorGravity="top"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 2017-01-10
      • 1970-01-01
      • 1970-01-01
      • 2017-03-21
      相关资源
      最近更新 更多