【问题标题】:Not able to set height to custom made tab layout无法将高度设置为自定义选项卡布局
【发布时间】:2016-02-25 15:07:42
【问题描述】:

我想为我的应用程序创建自定义选项卡布局。问题是我无法设置相同的高度。

请帮忙解决问题。

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="@dimen/tab_height"
        android:background="@color/colorAccent"/>

custom_tab.xml

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/tabIcon"
        android:layout_width="30dp"
        android:layout_height="30dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|right"
        android:background="@drawable/white_circle"
        android:gravity="center"
        android:text="2"
        android:textColor="@color/colorAccent"/>
</FrameLayout>

<TextView
    android:id="@+id/tabName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@drawable/tab_text_selection_states"
    android:textSize="14sp"/>

</LinearLayout>

【问题讨论】:

    标签: android material-design android-tablayout


    【解决方案1】:

    在 TabLayout 内将 android:layout_height="wrap_content" 更改为 android:layout_height="100dp" 或您想要多少 dps。

    【讨论】:

    • 知道了!其实我之前试过这个,但是出了点问题。所以我看不到预期的结果。所以,我发布了这个问题。现在解决了。。谢谢。
    【解决方案2】:

    不要将android:layout_height="wrap_content" 用于您的 TabLayout。只需使用android:layoutHeight="@dimen/tab_height"。您的 FrameLayout 也是如此。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-23
      • 2021-06-13
      • 1970-01-01
      • 2011-10-08
      • 1970-01-01
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      相关资源
      最近更新 更多