2016-05-16 37 views
0

我有点与标签布局合作来实现一个底部导航,这有点工作得很好。我被卡住的一个问题是,如果我按下一个选项卡或将其保持更长时间,则不会将全部高度变为彩色,只是图像的位置和下面的文本。为了演示我花了一个形象:Android TabLayout按下标签没有正确实现

Demonstration of the design problem

我设定的高度在TabLayout到56dp和指定的TabLayout的一个标签,此代码:

<?xml version="1.0" encoding="utf-8"?> 
 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:layout_width="wrap_content" 
 
    android:layout_height="wrap_content" 
 
    android:background="?attr/selectableItemBackground" 
 
    android:gravity="center" 
 
    android:orientation="vertical"> 
 

 
    <ImageView 
 
     android:id="@+id/icon" 
 
     android:layout_width="24dp" 
 
     android:layout_height="24dp" 
 
     android:scaleType="centerInside" /> 
 

 
    <TextView 
 
     android:id="@+id/title" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:ellipsize="end" 
 
     android:maxLines="1" 
 
     android:textAllCaps="false" 
 
     android:textColor="@color/tab_color" 
 
     android:textSize="12sp" 
 
     tools:text="Recents" /> 
 
</LinearLayout>

TabLayout定义在活动中:

<android.support.design.widget.TabLayout 
 
     android:id="@+id/tab_layout_bottom" 
 
     style="@style/AppTabLayout" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="56dp" 
 
     android:background="?attr/colorPrimary" 
 
     />

+0

做线性布局match_parent的高度和宽度,并尝试它。 –

+0

这没有帮助。我已经尝试过了。 –

+0

请分享您的tabLayout xml –

回答

0

我删除了TabLayout和使用从GitHub BottomBar由于材料设计适应。