简体   繁体   English

如何在android中的选项卡顶部显示选项卡指示器?

[英]How to show tab indicator on top of tab in android?

在此处输入图片说明 I have an app in which I have added TabLayout with three tabs.我有一个应用程序,我在其中添加TabLayout带有三个选项卡的TabLayout I want to show tab indicator from bottom to top but the problem is that when I show indicator from bottom to top tab icon also rotate.How do I resolve this issue?我想从下到上显示标签指示器,但问题是当我从下到上显示指示器时,标签图标也会旋转。我该如何解决这个问题?

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

I have similar requirement in my previous application我在之前的申请中有类似的要求

Please try below code it works perfectly for me请尝试下面的代码它对我来说完美无缺

//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);
                    }
                }

This is working nicely in my application and not creating any issue till now.Another way is you need to make custom tab to manage this.这在我的应用程序中运行良好,直到现在还没有产生任何问题。另一种方法是您需要制作自定义选项卡来管理它。

Hope this helps you...if any issue please ask me...希望这对你有帮助...如果有任何问题请问我...

将此添加到您的 TabLayout XML 中

app:tabIndicatorGravity="top"

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

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