Mehul Tank Mehul Tank - 2 months ago 13
Android Question

how to add RelativeLayout after AppbarLayout in CoordinateLayout

I am using

CoordinateLayout
, in that
AppBarLayout
and below
ScrollView
,
AppbarLayout
and
ScrollView
are overlap to each other. how to set ScrollView below to AppBarLayout. let me know thnks

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_blue"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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.v7.widget.Toolbar>


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

<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/padding_medium"
android:layout_marginRight="@dimen/padding_medium"
android:scrollbars="none">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_verysmall"
android:gravity="center"
android:orientation="vertical">


</LinearLayout>

</ScrollView>

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

Answer

Just Add like this way

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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.v7.widget.Toolbar>


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

<RelativeLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent">
   <ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="@dimen/padding_medium"
    android:layout_marginRight="@dimen/padding_medium"
    android:scrollbars="none">

     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/padding_verysmall"
            android:gravity="center"
            android:orientation="vertical">


    </LinearLayout>

   </ScrollView>

</RelativeLayout>

put your ScrollView Inside the RelativeLayout. and also add your Activity or layout context in RelativeLayout.