本文介绍了支持Android设计TabLayout:重心和模式滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用新的设计TabLayout在MUY项目。我想要的布局,以适应每个屏幕大小和方向,但它可以correclty在一个orientantion可见。

我处理的重力和模式的设定我tabLayout为:

  tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
 

因此​​,我预计,如果没有房,tabLayout是滚动的,但如果有空间,它的中心。

从指南:

所以GRAVITY_FILL仅与MODE_FIXED兼容,但在IS不指定任何GRAVITY_CENTER,我希望它是与MODE_SCROLLABLE兼容的,但是这是我开始使用GRAVITY_CENTER和MODE_SCROLLABLE

因此​​,它是使用SCROLLABLE在两个方向,但它不使用GRAVITY_CENTER

这是我所期望的景观;但有这个,我需要设置MODE_FIXED,所以我得到的画像是:

为什么GRAVITY_CENTER不工作的SCROLLABLE如果tabLayout适合屏幕?有什么办法来设置dinamically重力和模式(和看什么我期待)?

非常感谢你!

编辑:这是我的TabLayout的布局:

 < android.support.design.widget.TabLayout
    机器人:ID =@ + ID / sliding_tabs
    机器人:layout_width =match_parent
    机器人:背景=@色/ orange_pager
    机器人:layout_height =WRAP_CONTENT/>
 

解决方案

标签重力只影响 MODE_FIXED

一个可行的办法是设置你的 layout_width WRAP_CONTENT layout_gravity center_horizo​​ntal

 < android.support.design.widget.TabLayout
    机器人:ID =@ + ID / sliding_tabs
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =center_horizo​​ntal
    应用程序:tabMode =滚动/>
 

如果凸起为比屏幕的宽度越小, TabLayout 本身也将较小,因为重力将被居中。如果选项卡是大于屏幕宽度, TabLayout 将匹配屏幕宽度和滚动激活。

I am trying to use the new Design TabLayout in muy project. I want the layout to adapt to every screen size and orientation, but it can be seen correclty in one orientantion.

I am dealing with Gravity and Mode setting my tabLayout as:

    tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

So I expect that if there is no room, the tabLayout is scrollable, but if there is room, it is centered.

From the guides:

So GRAVITY_FILL is compatible only with MODE_FIXED but, at is doesn't specify anything for GRAVITY_CENTER, I expect it to be compatible with MODE_SCROLLABLE, but this is what I get using GRAVITY_CENTER and MODE_SCROLLABLE

So it is using SCROLLABLE in both orientations, but it is not using GRAVITY_CENTER.

This is what I would expect for landscape; but to have this, I need to set MODE_FIXED, so what I get in portrait is:

Why is GRAVITY_CENTER not working for SCROLLABLE if the tabLayout fits the screen?Is there any way to set dinamically gravity and mode (and to see what I am expecting)?

Thank you very much!

EDITED: This is the Layout of my TabLayout:

<android.support.design.widget.TabLayout
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:background="@color/orange_pager"
    android:layout_height="wrap_content" />
解决方案

Tab gravity only effects MODE_FIXED.

One possible solution is to set your layout_width to wrap_content and layout_gravity to center_horizontal:

<android.support.design.widget.TabLayout
    android:id="@+id/sliding_tabs"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    app:tabMode="scrollable" />

If the tabs are smaller than the screen width, the TabLayout itself will also be smaller and it will be centered because of the gravity. If the tabs are bigger than the screen width, the TabLayout will match the screen width and scrolling will activate.

这篇关于支持Android设计TabLayout:重心和模式滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 03:53