android coordinatorLayout + tabLayout(底部)+ viewPager发生错误
我使用协调器布局作为活动的根布局(activity_main,其布局代码如下)。在这里面我有一个android coordinatorLayout + tabLayout(底部)+ viewPager发生错误
- AppBarLayout里面有一个工具栏
- ViewPager
- TabLayout
问题是我的viewpager有recyclerView/cardview描述数据的列表和最后一个元素在列表中被tabLayout覆盖。任何解决方案(目前最小的版本一起工作是豆形软糖,但这以下的棒棒糖) click here to view screen with error
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/container"
android:background="?attr/colorPrimary"
android:layout_gravity="bottom"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabBackground="@drawable/tab_color_selector"
android:layout_alignParentBottom="true"
app:tabSelectedTextColor="@color/colorPrimary"
app:tabIndicatorColor="@color/colorPrimary" />
以下属性添加到您的recyclerView和检查
<RecyclerView
android:clipToPadding="false"
android:paddingBottom="50dp"/>
你有这个问题的原因是因为如TabLayout
正在ViewPager
之前绘制。现在有多种方法可以解决此问题,但其中一种更简单的方法是将ViewPager
和TabLayout
包装在Relativelayout
中,并将ViewPager
从TabLayout
后面的图纸中限制出来。
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize">
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/tab_layout"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabMode="fixed"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
它将tabLayout完全取出屏幕 –
你能分享一些你认为有用的其他解决方案吗? –
@gauravarora从'RelativeLayout'中删除 'android:layout_marginTop =“?attr/actionBarSize”',如果这样做不起作用,那么尝试将'android:layout_marginBottom =“?attr/actionBarSize”' '加入'RelativeLayout' –
它的工作! thanx –
欢迎........ – mdDroid