底部 tablayout 内的回收器不显示最后一行

Recycler inside bottom tablyout not showing last row

我有一个坐标布局,里面有自定义 ViewPager 和底部 TabLayout现在的问题是 ViewPager 的片段之一的 RecyclerView 无法正确滚动。它隐藏了最后一行。

tablayout.xml

 <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

<CustomViewPager    
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            style="@style/AppTabLayout"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_gravity="bottom"
            android:layout_alignParentBottom="true"
            android:background="@color/colorBottomBar"
            />
        </RelativeLayout>

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

CustomViewPager

public class CustomViewPager extends ViewPager {
            private boolean enabled;

            public CustomViewPager(Context context, AttributeSet attrs) {
                super(context, attrs);
                this.enabled = true;
            }

            @Override
            public boolean onTouchEvent(MotionEvent event) {
                if (enabled)
                    return super.onTouchEvent(event);
                else
                    return false;
            }

            @Override
            public boolean onInterceptTouchEvent(MotionEvent event) {
                return enabled && super.onInterceptTouchEvent(event);
            }

            public void setPagingEnabled(boolean enabled) {
                this.enabled = enabled;
            }

            public boolean isPagingEnabled() {
                return enabled;
            }

        }

ViewPager Fragmet 有 recyclerview

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

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="@color/toolbarColor"
        android:id="@+id/tool_bar"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">



        <ImageView
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_marginLeft="30dp"
            android:layout_marginStart="30dp"
            android:id="@+id/reload"
            android:clickable="true"
            android:src="@drawable/icon_refresh"/>

    </android.support.v7.widget.Toolbar>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:layout_below="@+id/tool_bar"
        android:orientation="horizontal"
        android:id="@+id/sort_layout"
        android:background="@android:color/white"
        android:weightSum="1">



    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recyclerview"
        android:scrollbars="vertical"
        android:background="@color/colorBottomBar"
        android:layout_below="@+id/sort_layout"/>

</RelativeLayout>

在上图中,您看到 RecyclerView 的最后一行并不完全可见。

在您的 ‍tablayout.xml 中使用此代码代替您的:

   <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <CustomViewPager    
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                style="@style/AppTabLayout"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_gravity="bottom"
                android:layout_alignParentBottom="true"
                android:background="@color/colorBottomBar"/>
        </RelativeLayout>
    </android.support.design.widget.CoordinatorLayout>

将自定义分页器和选项卡布局放在相对布局中,并像这样在选项卡布局上方设置自定义分页器

<android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

        <CustomViewPager    
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/@+id/tab_layout
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            style="@style/AppTabLayout"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_gravity="bottom"
            android:layout_alignParentBottom="true"
            android:background="@color/colorBottomBar"
            />
        </RelativeLayout>

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