1

I can't scroll my RecyclerView to the end. It cut off my last element and I completly don't know why. I have another RecyclerView in my project, which also seems to be broken. Broken RecyclerView

Here is my layout code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container"
    android:padding="10dp">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cv"
        app:cardCornerRadius="2dp"
        app:cardUseCompatPadding="true">

        <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="220dp"
            android:orientation="horizontal">

(...)

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/textView17"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="HISTORIA"
        android:id="@+id/textView17"
        android:layout_below="@+id/cv"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

Another broken RecyclerView:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.praca_inz.Fragments.PetrolFragment">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:scaleType="center"
        android:src="@drawable/ic_editor_mode_edit"
        android:layout_marginBottom="70dp"
        android:layout_marginRight="15dp"
        android:layout_marginEnd="15dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

Any ideas, because I don't have any.

3
  • 1
    Seems like your content is under the navigation bar layer. Using CollapsingToolbarLayout at main activity layout can cause this problem. Oct 28, 2015 at 20:29
  • @oguzhand I don't have CollapsingToolbar. Here is my MainActivity layout: pastebin.com/mPwvb0up When I deleted last line in ViewPager app:layout_behavior="@string/appbar_scrolling_view_behavior" I get it looking like this: i.imgur.com/JYI0j18.gif RecyclerView looks good, but everything else is "higher". Oct 28, 2015 at 20:51
  • 1
    My mistake, sorry. It was CoordinatorLayout, not CollapsingToolbarLayout. There are some bugs I have seen while using it. One of them is same as yours. You can try to set bottom padding size at toolbar height. It can help in this case. Oct 28, 2015 at 20:59

6 Answers 6

1

You've got an issue in your first layout. In a RelativeLayout, a match_parent sized element will have exactly the same size as the layout itself. That's the case of your RecyclerView. However, it's not at the top of the layout, as it's below the @+id/textView17 TextView. So you're missing roughly 250~300dp of your RecyclerView (card's + text's height). You should probably use a vertical LinearLayout in this case, that's exactly what they're made for. Just set the RecyclerView's height to 0 and weight to 1.

1
  • Changing layout type to LinearLayout (vertical) didn't helped me. Also second tip with RecyclerView dimensions dosen't work. Oct 29, 2015 at 8:43
0

You should set padding bottom in your RecyclerView. Like this:

<android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/textView17"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:paddingBottom="20dp" />

I hope help you, and sorry for my bad english.

1
  • Thanks for comment but I've solved my problem by adding padding to ViewPager. I belive your solution also works, but mine is a little bit more universal, because in my case I set it once for every layout, but in your case I'd need to set it in every RecyclerView. Oct 28, 2015 at 21:46
0

There was a problem with ViewPager in MainActivity layout. The solution was to set a paddingTop parameter, to 105dp (to cover Toolbar and TabLayout) and delete app:layout_behavior="@string/appbar_scrolling_view_behavior" parameter.

Before:

<android.support.v4.view.ViewPager
   android:id="@+id/viewpager"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   app:layout_behavior="@string/appbar_scrolling_view_behavior"  /> 

After:

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="105dp"/>

Thank you @oguzhand, for directing me to solution!

1
  • Well you should definitely not rely on an hard-coded padding for this kind of use. Either use a LinearLayout or the layout_below attribute in a RelativeLayout. I don't really see how this fixed your whole problem. Oct 28, 2015 at 22:27
0

Add alignParentBottom="true" to the recyclerView. That should pin it to the bottom edge and the top will be pinned to the textview via the layoutBelow tag you already have in place

1
  • Unfortunately it didn't helped me. Oct 29, 2015 at 8:44
0

you can use android:layout_height="0dp" in recyclerview

 `<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rcListDevice"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        ...
 />`

it worked for me. (I used ConstraintLayout in parent)

0
<androidx.recyclerview.widget.RecyclerView
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/addUser"
        app:layout_constraintLeft_toLeftOf="parent"

        android:layout_marginTop="20dp"
        android:layout_marginBottom="80dp"
        android:id="@+id/recycleruserDetails"
        app:layout_constraintVertical_bias="0.0"
        android:layout_width="match_parent"
        android:layout_height="0dp" />

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.