young_08 young_08 - 4 days ago 5
Android Question

Recycler inside bottom tablyout not showing last row

I have a coordinate layout inside which there is custom

ViewPager
and bottom TabLayout. Now issue is
RecyclerView
of one of fragment of
ViewPager
not scrolling properly. Its hiding the last row.


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

In above picture , you see that last row of
RecyclerView
is not completely visible.

Answer

Put custom pager and tab layout in relative layout and set custom pager above tab layout like this

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