How to put RelativeLayout inside CoordinatorLayout

后端 未结 3 1775
星月不相逢
星月不相逢 2020-12-30 02:01

I\'m trying to recreate the search box as it is in Airbnb Android app. So I\'m using CoorinatorLayout with Toolbar and RecyclerView

相关标签:
3条回答
  • I was trying to do something a little similar, but with an ad banner at the bottom of the screen. My solution was to wrap the RelativeLayout outside the CoordinatorLayout as so:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
      <android.support.design.widget.CoordinatorLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_above="@+id/ad_view">
    
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
          <android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              app:layout_scrollFlags="scroll|enterAlways"
              app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/my_list_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
      </android.support.design.widget.CoordinatorLayout>
    
      <com.google.android.gms.ads.AdView
          android:id="@+id/ad_view"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_alignParentBottom="true"
          android:layout_gravity="center|bottom"
          app:adSize="SMART_BANNER"
          app:adUnitId="@string/admob_id" />
    
    </RelativeLayout>
    

    The toolbar properly hides when scrolling inside the RecyclerView and everything seems to be working just fine. I would imagine if you followed a similar principle you should be good-to-go.

    0 讨论(0)
  • 2020-12-30 02:30

    If you want remove status bar white colour, you must remove the next line

    <item name="android:statusBarColor">@android:color/transparent</item>`
    

    in v21/styles.xml

    Thanks for example.

    0 讨论(0)
  • 2020-12-30 02:39
    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/slidingLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/red"
                app:layout_scrollFlags="scroll|enterAlways"/>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="50dp"
                android:layout_marginRight="50dp"
                android:layout_marginTop="20dp"
                android:background="@drawable/rounded_background"
                android:orientation="horizontal"
                android:padding="6dp"
                app:layout_scrollFlags="scroll|enterAlways">
    
                <EditText
                    android:id="@+id/search"
                    android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:layout_weight="6"
                    android:background="@null"
                    android:fontFamily="sans-serif-light"
                    android:hint="Unesite grad"
                    android:paddingLeft="16dp"
                    android:paddingStart="16dp"/>
    
                <ImageView
                    android:id="@+id/cancelSearch"
                    android:layout_width="0dp"
                    android:layout_height="40dp"
                    android:layout_weight="1"
                    android:padding="10dp"
                    android:src="@drawable/ic_cancel" />
            </LinearLayout>
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_below="@id/appbar"
            android:background="#ffffff"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    </android.support.design.widget.CoordinatorLayout>
    

    Check if this works for you.

    0 讨论(0)
提交回复
热议问题