0

I want my RecyclerView not to pass my guideline. Is there any other way rather than using NestedScrollView as a parent for my RecyclerView?enter image description here

[enter image description here][2]

<androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/textInputSearch"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="16dp"
                    android:hint="@string/homeSearchHint"
                    android:layoutDirection="rtl"
                    app:boxBackgroundMode="none"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:startIconDrawable="@drawable/ic_search">

                    <com.google.android.material.textfield.TextInputEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/shape_search_field"
                        android:inputType="text"
                        android:maxLines="1"
                        android:textSize="14sp" />

                </com.google.android.material.textfield.TextInputLayout>

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recyclerHomeArticle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="16dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/textInputSearch" />

                <androidx.constraintlayout.widget.Guideline
                    android:id="@+id/guideline1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    app:layout_constraintGuide_percent=".7" />


</androidx.constraintlayout.widget.ConstraintLayout>

2 Answers2

0

This is doable using the ConstraintLayout as the parent layout and using a Guide to specify where your RecyclerView should stop.

See this old answer to a similar question.

Update

Set the following properties

android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/guideline1" 

As already suggested in the linked answer.

NiklasLehnfeld
  • 984
  • 6
  • 14
  • What if the list has only 1 item? There is gonna be a horizontal RecyclerView below this vertical one and both of them must be visible no matter how many items each of them has. The reason I placed the Guideline there was that. I wanted to set the bottom constraint of my vertical list to that.\ – Hossein Mirzazadeh Aug 13 '20 at 13:31
0

Few Things..

1.give recyclerView height as 0dp

2.and add its bottom contraint to parent bottom

2.remove guidlines as there is no use in this layout

Try This

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputSearch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:hint="@string/homeSearchHint"
        android:layoutDirection="rtl"
        app:boxBackgroundMode="none"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:startIconDrawable="@drawable/ic_search">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/shape_search_field"
            android:inputType="text"
            android:maxLines="1"
            android:textSize="14sp" />

    </com.google.android.material.textfield.TextInputLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerHomeArticle"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textInputSearch" />


</androidx.constraintlayout.widget.ConstraintLayout>
chand mohd
  • 2,363
  • 1
  • 14
  • 27
  • There is gonna be a horizontal RecyclerView below this vertical one and both of them must be visible no matter how many items each of them has. The reason I placed the Guideline there was that. I wanted to set the bottom constraint of my vertical list to that. – Hossein Mirzazadeh Aug 13 '20 at 13:30