内部底部的循环器没有显示最后一排

时间:2016-11-29 05:04:28

标签: android android-viewpager android-tablayout bottom-sheet

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

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>

enter image description here

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

2 个答案:

答案 0 :(得分:1)

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>

答案 1 :(得分:1)

将自定义寻呼机和标签布局放在相对布局中,并将自定义寻呼机设置在标签布局上方,如此

<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>