bobby I.
bobby I.

Reputation: 113

Last item covered by bottom navigation

So, I have this problem. My last item of recyclerview is covered by my bottom navigation. The bottom navigation is in activity. The recyclerview is in the fragment. I not found the answer.

Here is my fragment layout, which contain the recyclerview

<android.support.constraint.ConstraintLayout 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="wrap_content"
    tools:context=".PromoFragment">

    <!-- TODO: Update blank fragment layout -->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/promo_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginBottom="110dp">

    </android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>

Here is my item layout that I use in recyclerview

<android.support.constraint.ConstraintLayout 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="wrap_content"
    android:orientation="vertical"
    android:padding="5px">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:id="@+id/card_pertama"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

               <include layout="@layout/card_promo_layout"/>

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

</android.support.constraint.ConstraintLayout>

Here is the image of the result from my code

enter image description here

Upvotes: 6

Views: 1924

Answers (5)

Shubham
Shubham

Reputation: 76

In your adapter class add this:

override fun onBindViewHolder(holder: LinkViewHolder, position: Int) {
    val link = links[position]

    
    // this will solve the problem 
    if (position == links.size - 1){
        val marginLayoutParams = holder.itemView.layoutParams as ViewGroup.MarginLayoutParams
        marginLayoutParams.bottomMargin = 300
        holder.itemView.layoutParams = marginLayoutParams
    }

If you want see the full doc, refer this: Documentation

Upvotes: 0

Aamir Khan
Aamir Khan

Reputation: 99

You can use this android:clipToPadding="false" and add the android:paddingBottom="height of the navigation bar" attributes with your RecyclerView

    <android.support.v7.widget.RecyclerView
            android:id="@+id/promo_recyclerview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:paddingBottom="height of the navigation bar"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginBottom="110dp"/>

Upvotes: 1

Oleg Golomoz
Oleg Golomoz

Reputation: 532

Add android:paddingBottom="56dp" to your Fragment that contains RecyclerView or to the closest parent layout of RecyclerView. For example:

<android.support.constraint.ConstraintLayout 
    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="wrap_content"
    android:paddingBottom="56dp"
    tools:context=".PromoFragment">

    <!-- TODO: Update blank fragment layout -->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/promo_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
    </android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>

P.S. 56dp - is the height of BottomNavigationView according to Material Design. So value of paddingBottom must be the same as the height of BottomNavigationView

Upvotes: 4

Blackbelt
Blackbelt

Reputation: 157477

I had the same issue. I did fixed it using an item decoration for the RV and offsetting the latest item of the height of the bottom navigation bar (which is usually the same height of the action bar). EG

 mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
           @Override
           public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
               int position = parent.getChildAdapterPosition(view);
               if (position == parent.getAdapter().getItemCount() - 1) {
                      outRect.bottom = bottomMargin;
                }
             }
   });

Upvotes: 1

Jimale Abdi
Jimale Abdi

Reputation: 2864

Change your bottom Navigation into this

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/navigationView" />

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigationView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/windowBackground"
    android:layout_alignParentBottom="true"
    app:menu="@menu/your_menu" />

And change your Layout into RelativeLayout

Upvotes: 1

Related Questions