高度在TabLayout上不起作用

Ali*_*Ali 2 xml android android-elevation

我正在ViewPager内的TabLayout上设置高程,但根本没有显示。我在stackoverflow上尝试了很多答案,但无法解决问题。在CoordinatorLayout中设置android:clipToPadding =“ false”也无法解决问题。任何帮助,将不胜感激。这是我正在使用的布局的xml,但现在正在提升高度:

 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <View
        android:id="@+id/statusBarBackground"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:clipToPadding="false" >

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false" >

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </ScrollView>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill"
            app:elevation="3dp" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

Khe*_*raj 5

  • 为了让阴影可见,你必须设置背景上的TabLayout。它可以是与窗口背景相同的颜色(只要是不带Alpha的纯色即可)。

  • 同样,您必须给它Tablayout留出一定的余量才能看到高程。 您应该给的最低保证金elevation

    android.support.design.widget.TabLayout ... android:elevation="6dp" android:margin="10dp" // margin > elevation android:background="@color/white" />