1

From 2 months I'm playing with ConstrainLayout but every time I face a few problems and after spending a lot of time I find the solution but now I'm in a deathlock. My view upper part is hidden by the status bar and lower part also hidden by navigation bar.

How my view display in device overlap view

Here you can see my AppBar is below status bar and also the RecyclerView last item is not showing complete. It's some view is unvisible.

I'm not sure where is the problem, previously I solve such kinds of problems by adding android:fitsSystemWindows="true" but now it's not working. And also it's behave different when I try applying googles result.

This is my view xml code

<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="wrap_content"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay"
    app:layout_constraintBottom_toTopOf="@id/shop_recycler_view"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/shop_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:fitsSystemWindows="true"
    android:scrollbars="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/app_bar"
    tools:listitem="@layout/shop_list_recycler_view_row" />
</android.support.constraint.ConstraintLayout>
Rhidoy
  • 123
  • 1
  • 12

1 Answers1

0

I'd use CoordinatorLayout instead of ConstraintLayout for the future features adding like hiding Toolbar or etc. However, using CoordinatorLayout seems to be the best choice here:

<android.support.design.widget.CoordinatorLayout 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"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/shop_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:fitsSystemWindows="true"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:listitem="@layout/shop_list_recycler_view_row" />

</android.support.design.widget.CoordinatorLayout>
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
  • 1
    thanks for your answer, I will use CoordinatorLayout in future, and now I solved this problem by adding RecyclerView height to 0dp. – Rhidoy Oct 15 '18 at 21:40
  • 1
    Why 0? Are you using `LinearLayout` as the root layout forthe `RecyclerView`? You don't need to make it 0. Just use `match_parent`. please consider accepting the answer if it helped. – ʍѳђઽ૯ท Oct 16 '18 at 07:09