0

Code for XML :-

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.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=".MainActivity">

    <include
        android:id="@+id/toolbar1"
        layout="@layout/toolbar_standalone" />


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />
    </androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

please help to correct the code. so toolbar does not overide the recycler view. I have laready tried this changes but not working perfectly.

app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
Rahul
  • 117
  • 1
  • 14
  • It's expected behavior since you use `app:layout_constraintTop_toTopOf="parent" ` instead of `app:layout_constraintTop_toBottomOf="@id/toolbar1"` – Thracian Oct 13 '20 at 16:54
  • Thanks it working fine – Rahul Oct 13 '20 at 17:00
  • I suggest you use CoordinatorLayout along with `app:layout_behavior`. See the answer for [Android RecyclerView below Toolbar](https://stackoverflow.com/questions/31306884/android-recyclerview-below-toolbar). – Nicolas Oct 13 '20 at 17:03

1 Answers1

0

you can width and height to layout

you can set the default action bar size

android:layout_height="?attr/actionBarSize"

and use layout_constraintTop_toBottomOf

  <androidx.constraintlayout.widget.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=".MainActivity">

    <include
        android:id="@+id/toolbar1"
        layout="@layout/toolbar_standalone"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"/>


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar1" />
</androidx.constraintlayout.widget.ConstraintLayout>
Javad Dehban
  • 1,282
  • 3
  • 11
  • 24