2017-09-24 40 views
0

我在ViewPager內的TabLayout上設置高程,但根本沒有顯示。我在stackoverflow上嘗試了很多答案,但無法解決問題。在CoordinatorLayout中設置android:clipToPadding =「false」也不能解決問題。任何幫助,將不勝感激。下面是我用的,但現在越來越海拔佈局的XML:仰角無法在TabLayout上工作

<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> 
+0

只需將App:elevation =「0dp」添加到AppBarLayout即可。 – ZeroOne

+1

@ZeroOne將App:elevation =「0dp」添加到AppBarLayout不起作用。 – Ali

+1

哦對不起..改變0dp爲其他值:6dp .. – ZeroOne

回答

2

更改應用:海拔= 「3DP」 到Android:海拔= 「3DP」

<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" 
     change ----> android:elevation="3dp" /> 
+0

仍然沒有海拔。儘管我正在使用支持庫。 https://stackoverflow.com/a/33054366/6050536 – Ali

2
  • 要進行陰影顯示,您必須在TabLayout上設置背景。它可以與你的窗口背景顏色相同(只要它是一個沒有alpha的純色)。
  • 此外,你必須給它Tablayout餘量看到海拔。 最低保證金應elevation你給

    android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:elevation="6dp" android:margin="10dp" android:background="@color/white" />

0

你有幾個與你的佈局問題:

  1. 更改應用:海拔= 「3DP」 - >機器人:海拔=」 3dp「
  2. add your android:background =」@ color/colorPrimary「to your TabLayout
  3. Add android:paddingBottom =」3dp「to你的AppBarLayout

主要想法是,如果視圖背景是透明的或父視圖正在剪裁你的陰影,你的影子將不會顯示。

你仍然會有一些問題需要解決,但是是一個開始。

+0

仍然沒有陰影和填充使TabLayout上升。 – Ali

+0

如果你說這會導致你的TabLayout上升,這意味着投下陰影。你怎麼會有深度感知?所以你現在的問題是你的ScrollView的高程低於你的TabLayout,這意味着TabLayout的陰影在ScrollView上。 –

+0

TabLayout在ScrollView下方,所以我不認爲它們的陰影重疊。 – Ali