0

У меня есть tablayout внутри AppBarLayout. Я пытаюсь добавить теневой вид ниже tabbarlayout для версий до леллипопа. Появится теневое представление, однако, когда я прокручиваю вниз, теневое представление не кажется прозрачным. Это выглядит так, как будто есть надпись ниже tablayout, между tabindicator и shadow. Однако, если я использую один и тот же вид теней только под панелью инструментов, он кажется прозрачным при прокрутке вверх. Может ли кто-нибудь сказать мне, есть ли что-то другое, чтобы добавить тень для табуляции?tablayout shadow/elevation for pre-lollipop

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) не будет знать, как выложить следующий вид (ваш просмотрщик), чтобы тень слегка перекрывала содержимое, что должно нарисовать последним, так что верхняя часть пейджера обзора не покрывает тень

+0

Извините, пожалуйста, весь код. Не могли бы вы рассказать мне, где именно изменить его на FrameLayout, так как он находится в CoordinatorLayout? – Sammys