在 Android Pre-lollipop 上单击另一个选项卡后,Tablayout 投影消失
Tablayout Drop Shadow Disappears after I click another tab on Android Pre-lollipop
我试图在tablayout 之后创建一个投影,但在我单击另一个选项卡或向下滚动其下方的视图寻呼机后它立即消失了。这是我向下滚动后发生的情况。
第一次加载后出现阴影:
向下滚动后,阴影消失:
单击另一个选项卡后,阴影也消失了:
但是当我再次向上滚动并点击回到它的第一个目的地时,阴影又出现了!
我已经搜索过 SO 但我似乎可以找到答案。希望你们能帮助我。
我的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_lane"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/lighter_purple_99"
android:elevation="4dp"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingTop="4dp">
<ImageView
android:id="@+id/img_lane_settings"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="right"
android:layout_marginRight="14dp"
android:src="@drawable/icn_settings" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
app:tabIndicatorColor="@color/white_100"
android:background="@color/lighter_purple_99"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:elevation="4dp"/>
<View
android:id="@+id/shadow_below_tabs2"
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_below="@+id/tabs2"
android:background="@drawable/shadow"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tabs2"
android:keepScreenOn="true"
tools:context="TabActivity" />
</RelativeLayout>
drawable/shadow.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="@android:color/transparent"
android:endColor="#ff000000"
android:angle="90">
</gradient>
</shape>
我已经试过了:
-- AppBarLayout 但是它有阴影背景所以看起来很难看。
希望你能帮助我。提前致谢!
解决了!
把shadow view放到viewpager下面就行了。这样,阴影将是最后一个显示并放置在 viewpager 顶部的。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_lane"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/lighter_purple_99"
android:elevation="4dp"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingTop="4dp">
<ImageView
android:id="@+id/img_lane_settings"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="right"
android:layout_marginRight="14dp"
android:src="@drawable/icn_settings" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
app:tabIndicatorColor="@color/white_100"
android:background="@color/lighter_purple_99"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:elevation="4dp"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tabs2"
android:keepScreenOn="true"
tools:context="com.dojomadness.lolsumo.activities.LaneActivity" />
<View
android:id="@+id/shadow_view"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_below="@id/tabs2"
android:background="@drawable/shadow"
/>
</RelativeLayout>
我试图在tablayout 之后创建一个投影,但在我单击另一个选项卡或向下滚动其下方的视图寻呼机后它立即消失了。这是我向下滚动后发生的情况。
第一次加载后出现阴影:
向下滚动后,阴影消失:
单击另一个选项卡后,阴影也消失了:
但是当我再次向上滚动并点击回到它的第一个目的地时,阴影又出现了!
我已经搜索过 SO 但我似乎可以找到答案。希望你们能帮助我。
我的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_lane"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/lighter_purple_99"
android:elevation="4dp"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingTop="4dp">
<ImageView
android:id="@+id/img_lane_settings"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="right"
android:layout_marginRight="14dp"
android:src="@drawable/icn_settings" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
app:tabIndicatorColor="@color/white_100"
android:background="@color/lighter_purple_99"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:elevation="4dp"/>
<View
android:id="@+id/shadow_below_tabs2"
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_below="@+id/tabs2"
android:background="@drawable/shadow"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tabs2"
android:keepScreenOn="true"
tools:context="TabActivity" />
</RelativeLayout>
drawable/shadow.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="@android:color/transparent"
android:endColor="#ff000000"
android:angle="90">
</gradient>
</shape>
我已经试过了:
-- AppBarLayout 但是它有阴影背景所以看起来很难看。
希望你能帮助我。提前致谢!
解决了!
把shadow view放到viewpager下面就行了。这样,阴影将是最后一个显示并放置在 viewpager 顶部的。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_lane"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/lighter_purple_99"
android:elevation="4dp"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingTop="4dp">
<ImageView
android:id="@+id/img_lane_settings"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="right"
android:layout_marginRight="14dp"
android:src="@drawable/icn_settings" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
app:tabIndicatorColor="@color/white_100"
android:background="@color/lighter_purple_99"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:elevation="4dp"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tabs2"
android:keepScreenOn="true"
tools:context="com.dojomadness.lolsumo.activities.LaneActivity" />
<View
android:id="@+id/shadow_view"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_below="@id/tabs2"
android:background="@drawable/shadow"
/>
</RelativeLayout>