1

I have two RecyclerView inside ScrollView. The second RecyclerView named "recyclerView_main_article" can't be shown completely. I mean its bottom was cut out. I tried to add extra View named "empty" under the RecyclerView to make some space. After I added "empty", "recyclerView_main_article" was shown completely but "empty" was shorter than its height. Here is XML.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_light">

    <android.support.constraint.ConstraintLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:id="@+id/view_title_line"
            android:layout_width="5dp"
            android:layout_height="24dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="16dp"
            android:background="@color/colorPrimary"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/textView_top_movie_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:text="@string/top_movie_title"
            android:textColor="@color/colorPrimary"
            android:textSize="20sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="@+id/view_title_line"
            app:layout_constraintStart_toEndOf="@+id/view_title_line" />

        <TextView
            android:id="@+id/textView_see_all_movies"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:text="@string/see_all"
            app:layout_constraintBottom_toBottomOf="@+id/view_title_line"
            app:layout_constraintEnd_toEndOf="parent" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView_main_video"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/view_title_line" />

        <View
            android:id="@+id/view_title_line2"
            android:layout_width="5dp"
            android:layout_height="24dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="32dp"
            android:background="@color/colorPrimary"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/recyclerView_main_video" />

        <TextView
            android:id="@+id/textView_top_article_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:text="@string/top_article_title"
            android:textColor="@color/colorPrimary"
            android:textSize="20sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="@+id/view_title_line2"
            app:layout_constraintStart_toEndOf="@+id/view_title_line2" />

        <TextView
            android:id="@+id/textView_see_all_articles"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:text="@string/see_all"
            app:layout_constraintBottom_toBottomOf="@+id/view_title_line2"
            app:layout_constraintEnd_toEndOf="parent" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView_main_article"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/view_title_line2" />

        <!--<View
            android:id="@+id/empty"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="@android:color/holo_orange_dark"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/recyclerView_main_article" />-->
    </android.support.constraint.ConstraintLayout>
</ScrollView>

I apply HORIZONTAL to the RecyclerViews by this Kotlin code.

recyclerView_main_video.layoutManager = LinearLayoutManager(this, OrientationHelper.HORIZONTAL, false)
recyclerView_main_article.layoutManager = LinearLayoutManager(this, OrientationHelper.HORIZONTAL, false)

I use Android Studio 3.0.1 and my recyclerview version is 26.1.0.

implementation 'com.android.support:recyclerview-v7:26.1.0'

What should I do?? I need your help.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163

3 Answers3

1

Using RecyclerView inside a ScrollView is a bad idea, the best practice is using a recyclerview and put everything you want to scroll inside it. If there is some views above your recycled items just make an header with is own viewHolder and put it in the first position of your recyclerView

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
weilin06
  • 11
  • 4
  • Thank you for your comment. I have two horizontal RecyclerViews and the total height of all views is higher than device height. That's why I wrapped them with ScrollView. NestedScrollView solved my problem. Thank you anyway. –  Feb 23 '18 at 01:54
1

Change ScrollView to NestedScrollView

Add android:paddingBottom="50dp" android:clipToPadding="false" in second recyclerview

For clipToPadding

Try this :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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:fillViewport="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_light">

    <android.support.constraint.ConstraintLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:id="@+id/view_title_line"
            android:layout_width="5dp"
            android:layout_height="24dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="16dp"
            android:background="@color/colorPrimary"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/textView_top_movie_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:text="@string/top_movie_title"
            android:textColor="@color/colorPrimary"
            android:textSize="20sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="@+id/view_title_line"
            app:layout_constraintStart_toEndOf="@+id/view_title_line" />

        <TextView
            android:id="@+id/textView_see_all_movies"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:text="@string/see_all"
            app:layout_constraintBottom_toBottomOf="@+id/view_title_line"
            app:layout_constraintEnd_toEndOf="parent" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView_main_video"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/view_title_line" />

        <View
            android:id="@+id/view_title_line2"
            android:layout_width="5dp"
            android:layout_height="24dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="32dp"
            android:background="@color/colorPrimary"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/recyclerView_main_video" />

        <TextView
            android:id="@+id/textView_top_article_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:text="@string/top_article_title"
            android:textColor="@color/colorPrimary"
            android:textSize="20sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="@+id/view_title_line2"
            app:layout_constraintStart_toEndOf="@+id/view_title_line2" />

        <TextView
            android:id="@+id/textView_see_all_articles"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:text="@string/see_all"
            app:layout_constraintBottom_toBottomOf="@+id/view_title_line2"
            app:layout_constraintEnd_toEndOf="parent" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView_main_article"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:paddingBottom="50dp"
            android:clipToPadding="false"
            android:layout_marginTop="8dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/view_title_line2" />

        <!--<View
            android:id="@+id/empty"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="@android:color/holo_orange_dark"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/recyclerView_main_article" />-->
    </android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
Community
  • 1
  • 1
Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
  • 1
    Thank you @VishvaDave. It works completely! I didn't know about NestedScrollView and the property "clipToPadding". This is my first Android app so I need to study harder! Thank you!! –  Feb 23 '18 at 01:41
  • 1
    @FESHIMO Happy to help :) Happy coding :) – Vidhi Dave Feb 23 '18 at 04:02
0

try to use NestedScrollView instead of ScrollView

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Mohamd Ali
  • 2,146
  • 4
  • 23
  • 30
  • Thank you. I didn't know NestedScrollView. The other user told me the detail so I chose it as the best answer, but thank you anyway. –  Feb 23 '18 at 01:47