0

我有一個在AppBarLayout內的tablayout。我正在嘗試在tabbarlayout下爲預先棒棒糖版本添加陰影視圖。陰影視圖顯示出來,然而當我向下滾動時,陰影視圖看起來不透明。它看起來好像在tablayicator和shadow之間的tablayout下有一個填充。但是,如果我在工具欄下方使用相同的陰影視圖,則在向上滾動時它似乎是透明的。有人能告訴我是否有任何不同的東西來爲tablayouts添加陰影嗎?tablayout陰影/海拔爲前棒棒糖

main_layout-

<android.support.v4.widget.DrawerLayout  
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     android:orientation="vertical"> 

     <include layout="@layout/include_coordinator_layout"/> 

    </LinearLayout> 

    <TextView 
     android:id="@+id/mtext_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:gravity="center" 
     android:visibility="gone"/> 

    <Button 
     android:id="@+id/mBtn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_below="@id/mtext_view" 
     android:text="@string/retry_button" 
     android:visibility="gone"/> 
</RelativeLayout> 

<android.support.design.widget.NavigationView 
    android:id="@+id/navView" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:background="@color/white" 
    android:fitsSystemWindows="true" /> 

</android.support.v4.widget.DrawerLayout> 

這是我include_coordinator_layout

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

    <include 
     android:id="@+id/toolbar" 
     layout="@layout/tool_bar" /> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tab_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMaxWidth="0dp" 
     app:tabGravity="fill" 
     app:tabMode="fixed" 
     android:background="@color/tab_layout_color"/> 

    <View 
     android:id="@+id/shadow_view" 
     android:layout_width="match_parent" 
     android:layout_height="5dp" 
     android:background="@drawable/toolbar_shadow" 
     /> 

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

<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

這是我toolbar_shadow繪製。

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <gradient 
     android:startColor="@android:color/transparent" 
     android:endColor="#88333333" 
     android:angle="90"/> 
</shape> 

回答

0

我猜你有你的佈局在LinearLayout

要麼

變化的LinearLayout到的RelativeLayout並添加android:layout_below="@+id/appbar"android:paddingTop="-5dp"android:clipToPadding="false"到您ViewPager(或使用ConstraintLayout和類似方法),開關工具欄和視圖尋呼機的順序

將其更改爲FrameLayout,對視圖進行重新排序,以便ViewPager首先放入android:layout_marginTop="@dimen/sizeOfToolBarAndTabsWithoutShadow",其中dimen是工具欄的標籤大小(不帶陰影)。你可能想這樣做,因爲我似乎記得一些帶有一些滾動視圖的視覺文物,並且clipToPadding

爲什麼?

因爲AppBarLayout視圖的大小包含了你的影子,所以任何基本視圖組(LinearLayout)都不知道如何將下一個視圖(你的viewpager)放在外面,這樣影子會稍微重疊內容 - 必須最後繪製,以便視圖尋呼機的頂部不覆蓋陰影

+0

抱歉包含了整個代碼。你能告訴我在哪裏把它改成FrameLayout,因爲它在CoordinatorLayout中嗎? – Sammys