Recyclerview in Coordinatorlayout cutting off last item

I have a Bottom Navigation Bar, and a frame layout which is the fragment container. So when a an icon on a Bottom Navigation Bar is clicked, the fragment above changes.

In one of the fragment, I have a coordinator layout, collapsing toolbar, and recycler view. At the moment, the data is just a dummy data.

The problem that I am encountering is that whenever that fragment is inflated for the first time, the Recyclerview works fine and shows all of the items in the list. But when I change the fragment and come back to this fragment again, the last item of the Recyclerview is being cut off and is being hidden behind the Bottom Navigation Bar.

Here is my code for activity_home_screen.xml

<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.smartinc.livesportstv.activities.HomeScreen">

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_nav"
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    app:itemBackground="?attr/colorPrimary"
    app:itemIconTint="@drawable/selector_bottombar_item"
    app:itemTextColor="@drawable/selector_bottombar_item"
    app:menu="@menu/bottombar_menu" />

<FrameLayout
    android:id="@+id/frame_fragmentholder"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/bottom_nav"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    />

Here is the fragment_events.xml

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
android:id="@+id/coordinator">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    >

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="@color/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:title="Events"
        app:expandedTitleTextAppearance="@style/TransparentText"
        app:collapsedTitleTextAppearance="@style/Toolbar_text_black"
        app:collapsedTitleGravity="center_horizontal"
        android:paddingEnd="20dp"
        android:fitsSystemWindows="true"
        >

        <!-- You can add views that you want to appear on the
             collapsing toolbar here -->

        <TextView
            android:id="@+id/events_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Events"
            android:textSize="30sp"
            android:textColor="@color/black"
            android:layout_marginTop="30dp"
            android:layout_marginStart="20dp"
            android:textStyle="bold"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="29 March, Thursday"
            android:textSize="20sp"
            android:textColor="@color/grey_800"
            android:layout_marginTop="70dp"
            android:layout_marginStart="20dp"
            />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            android:minHeight="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            android:gravity="center_horizontal"
            app:popupTheme="@style/AppTheme"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            />

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

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

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view_events"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    />


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Request"
    android:textSize="17sp"
    android:layout_gravity="end"
    android:textColor="@color/colorPrimaryDark"
    android:padding="10dp"
    android:layout_marginEnd="10dp"
    android:layout_marginTop="5dp"
    />

Here is HomeScreen.java

public class HomeScreen extends AppCompatActivity {

private BottomNavigationView bottomNavigationView;

private String fragName = "";

@Override
public void startActivity(Intent intent) {
    super.startActivity(intent);
    Constants.overridePendingTransitionEnter(this);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_screen);

    init();
    setMainFragment();
    setBottomNavigation();
}

private void init(){
    bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_nav);


}

private void setBottomNavigation(){
    bottomNavigationView.setOnNavigationItemSelectedListener(
            new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    switch (item.getItemId()) {
                        case R.id.bottombaritem_events:
                            if(!fragName.equals("events")) {
                                FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                                ft.setCustomAnimations(R.anim.left_slide_in, R.anim.right_slide_out);
                                ft.replace(R.id.frame_fragmentholder, new EventsFragment());
                                ft.commit();
                                fragName = "events";
                            }
                            return true;
                        case R.id.bottombaritem_channels:
                            FragmentTransaction ft2 = getSupportFragmentManager().beginTransaction();
                            if(fragName.equals("events")) {
                                ft2.setCustomAnimations(R.anim.right_slide_in, R.anim.left_slide_out);
                            } else {
                                ft2.setCustomAnimations(R.anim.left_slide_in, R.anim.right_slide_out);
                            }

                            ft2.replace(R.id.frame_fragmentholder, new ChannelsFragment());
                            ft2.commit();
                            fragName = "channels";
                            return true;
                        case R.id.bottombaritem_more:
                            if(!fragName.equals("more")) {
                                FragmentTransaction ft3 = getSupportFragmentManager().beginTransaction();
                                ft3.setCustomAnimations(R.anim.right_slide_in, R.anim.left_slide_out);
                                ft3.replace(R.id.frame_fragmentholder, new MoreFragment());
                                ft3.commit();
                                fragName = "more";
                            }
                            return true;
                    }
                    return false;
                }
            });
}

private void setMainFragment(){
    fragName = "events";
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.frame_fragmentholder, new EventsFragment());
    ft.commit();
}

@Override
public void onBackPressed() {
    super.onBackPressed();
    Constants.overridePendingTransitionExit(this);
}

}

And here is EventsFragment.java

public class EventsFragment extends Fragment {

private RecyclerView mRecyclerView;
private ArrayList<String> mData;

private CollapsingToolbarLayout collapsing_toolbar;

private Context mContext;

public EventsFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view =  inflater.inflate(R.layout.fragment_events, container, false);

    mContext = getActivity();

    final CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) view.findViewById(R.id.collapsing_toolbar);
    AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.app_bar);
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
        boolean isShow = true;
        int scrollRange = -1;

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (scrollRange == -1) {
                scrollRange = appBarLayout.getTotalScrollRange();
            }
            if (scrollRange + verticalOffset == 0) {
                collapsingToolbarLayout.setTitle("Events");
                isShow = true;
            } else if(isShow) {
                collapsingToolbarLayout.setTitle(" ");//carefull there should a space between double quote otherwise it wont work
                isShow = false;
            }
        }
    });

    // Initialize the RecyclerView
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view_events);
    setUpRecyclerView();

    return view;
}

private void setUpRecyclerView() {
    LinearLayoutManager llm = new LinearLayoutManager(mContext);
    llm.setAutoMeasureEnabled(true);
    mRecyclerView.setLayoutManager(llm);

    EventsAdapter eventsAdapter = new EventsAdapter(mContext);
    mRecyclerView.setAdapter(eventsAdapter);
}

}

Any help would be really appreciated. Thanks!

Remove this line from Event XML.

android:fitsSystemWindows="true"

And everything would be good to go.

RecyclerView cutting off last item, I'm also having the same problem. In my opinion this happened because you set the AppBarLayout XML attribute� android – RecyclerView cutting off last item . Posted by: admin May 13, 2020 admin May 13, 2020

override the fragment's setUserVisibleHint(),call view?.requestlayout()

 override fun setUserVisibleHint(isVisibleToUser: Boolean) {
        view?.requestLayout()
        super.setUserVisibleHint(isVisibleToUser)

    }

Recyclerview in Coordinatorlayout cutting off last item, But when I change the fragment and come back to this fragment again, the last item of the Recyclerview is being cut off and is being hidden behind the Bottom� off - recyclerview last item half visible android Android XML cutting off bottom half of layout (4)

  collapsingToolbarLayout.setTitle("Events");

this layout is hiding your last Recycler view, when this is shown your last item is hidden, when you set

  collapsingToolbarLayout.setTitle(""); 

your last item is visible.

So, set padding to parent layout accordingly

RecyclerView cutting off last item, see here last item is partially visible. How can i fix this? layout.xml <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget. CoordinatorLayout� android - resizing - recyclerview last item visible RecyclerView is cutting off the last item (4) Create a FrameLayout put the RecycerView in it having it match_parent for both the width and the height. You can size the frame layout however you want.

RecyclerView cutting off last item, CoordinatorLayout android:id="@+id/coordinator_layout" Recyclerview in Coordinatorlayout cutting off last item, But when I change the fragment and come � The RecyclerView uses a layout manager to position the individual items on the screen and determine when to reuse item views that are no longer visible to the user. To reuse (or recycle ) a view, a layout manager may ask the adapter to replace the contents of the view with a different element from the dataset.

RecyclerView is cutting off the last item, For some reason, the last element of the recyclerView is getting cut-off. AppBarLayout android:id="@+id/appbar_layout" android:layout_width=" match_parent"� Overview. CoordinatorLayout extends the ability to accomplish many of the Google's Material Design scrolling effects.Currently, there are several ways provided in this framework that allow it to work without needing to write your own custom animation code.

RecyclerViews inside ScrollView is cutting off the last item, RecyclerViews inside ScrollView is cutting off the last item - android. I have a ScrollView with a LinearLayout, and several different RecyclerView inside CoordinatorLayout> After loading the data into the RecyclerView, I need to change it's� The way this works is that we’re tapping into the layoutDependsOn method which fires off when a new layout event happens — as a result of a Snackbar being added, for example. Since we know the Snackbar is being added to a CoordinatorLayout we can make use of that and change its layout parameters.

Comments
  • I have tried disabling this part of the code, but the problem stays. And when the fragment is inflated for the first time, there’s no issue. The issue only starts after I come back to this fragment from another fragment