我在AppBarLayout中有一个表格布局。我正在尝试添加一个阴影视图下的标签栏布局,为前棒棒糖版本。阴影视图显示出来,但是当我向下滚动时,阴影视图看起来并不透明。它看起来就像是在tablayout下面,the指示器和阴影之间有一个填充。然而,如果我在工具栏下面使用相同的阴影视图,当我向上滚动时,它似乎是透明的。有没有人能告诉我有没有什么不同的地方可以为版面添加阴影?
主布局-
<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>发布于 2016-09-21 08:19:15
我猜您在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)都不知道如何布置下一个视图(您的视图分页程序),以便阴影与必须最后绘制的内容略有重叠,这样视图分页程序的顶部就不会覆盖阴影
https://stackoverflow.com/questions/39604963
复制相似问题