Search code examples
androidxmlandroid-layoutandroid-studiosearchview

Move RecyclerView After Click on SearchView


in my program i use a search view with recyclerview , in xml ,search view is above the recycler view now my problem is when i click on search view position, of recyclerview goes up and placed upon the search view.

i use ConstraintLayout and if i change the items layout connections , the button will also go up

enter image description here

enter image description here

XML :

<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="match_parent"
tools:context="com.example.user.classmanager.StudentList"
tools:layout_editor_absoluteY="25dp"
tools:layout_editor_absoluteX="0dp">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_StudentList"
    android:layout_width="0dp"
    android:layout_height="56dp"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme"
    tools:layout_constraintTop_creator="1"
    tools:layout_constraintRight_creator="1"
    app:layout_constraintRight_toRightOf="parent"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button_StudentList"
    android:layout_width="35dp"
    android:layout_height="35dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:text="B"
    app:layout_constraintBottom_toBottomOf="@+id/searchView_StudentList"
    app:layout_constraintHorizontal_bias="0.307"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toLeftOf="@+id/searchView_StudentList"
    app:layout_constraintTop_toTopOf="@+id/searchView_StudentList"
    app:layout_constraintVertical_bias="1.0"
    tools:layout_constraintLeft_creator="1"
    tools:layout_constraintTop_creator="1" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view_StudentList"
    android:layout_width="370dp"
    android:layout_height="450dp"
    android:layout_marginBottom="0dp"
    android:layout_marginEnd="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginStart="5dp"
    android:layout_marginTop="8dp"
    android:paddingLeft="7dp"
    android:paddingRight="7dp"
    android:paddingTop="22dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/searchView_StudentList"
    app:layout_constraintVertical_bias="0.371"
    tools:layout_constraintBottom_creator="1"
    tools:layout_constraintLeft_creator="1"
    tools:layout_constraintRight_creator="1" />

<SearchView
    android:id="@+id/searchView_StudentList"
    android:layout_width="300dp"
    android:layout_height="0dp"
    android:layout_marginEnd="7dp"
    android:layout_marginRight="7dp"
    android:layout_marginTop="13dp"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/toolbar_StudentList"
    tools:layout_constraintRight_creator="1"
    tools:layout_constraintTop_creator="1" />


Solution

  • Either remove the fixed height of the recyclerView

      android:layout_height="wrap_content" 
    

    or( better )remove this

      app:layout_constraintBottom_toBottomOf="parent"
    

    Constraint layout couldnt resolve the fixed height in dp and above the bottom of parent ( kinda sort of circular dependency )