Android TabLayout按下标签未正确完成

时间:2016-05-16 12:19:36

标签: android material-design 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>
&#13;
&#13;
&#13;

TabLayout在活动中定义:

&#13;
&#13;
<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"
        />
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

由于Material Design的改编,我删除了TabLayout并使用了Github的BottomBar。