【问题标题】:Change selected TabItem height更改选定的 TabItem 高度
【发布时间】:2018-05-24 02:27:45
【问题描述】:

我正在使用 TabLayout,并且正在寻找一种方法来更改所选 TabItem 的高度,因此这个会比其他的要大。为此,我尝试使用 TabIndicator,但我只能更改它的颜色和大小,而不是它的位置(它总是在 TabLayout 内,我需要将它放在它的正上方以达到我需要的效果)。

有没有办法使用选择器或在布局 xml 本身中实现这一点?

以下是所需效果的示例(左侧是选定的选项卡):

这是我目前的代码:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:tabIndicatorHeight="0dp"
            app:tabBackground="@drawable/nav_item_color_state">
                <android.support.design.widget.TabItem
                    android:id="@+id/tab1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Tab 1"/>
                <android.support.design.widget.TabItem
                    android:id="@+id/tab2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Tab 2"/>
        </android.support.design.widget.TabLayout>

</android.support.constraint.ConstraintLayout>

【问题讨论】:

  • 尝试在您的 TabLayout 上使用 android:clipChildren="false",并以编程方式更改高度。

标签: android xml layout tabs


【解决方案1】:

我最终使用了两个按钮并创建了两个不同的可绘制对象,以在其背景中用作选择/未选择状态。一点也不优雅,但它确实有效。

【讨论】:

    猜你喜欢
    • 2019-03-30
    • 2013-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多