13

Arama kutusunu Airbnb Android uygulamasında olduğu gibi yeniden oluşturmaya çalışıyorum. CoorinatorLayout'u Araç Çubuğu ve ile kullanıyorum. RecyclerView.RelativeLayout Koordinatörün içine nasıl yerleştirilirLayout

Ancak bu iki şey dışında Koordinatörün içine bir şey eklediğimde, o görünmüyor.

<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" /> 

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

<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.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" /> 

Ama aslında bu bile çalıştı, ben RecyclerView yukarıdaki arama kutusunu koyarak zahmetinden olurdu: İşte benim kodudur.

Herşeyi RelativeLayout içine koymaya çalıştım ama bu işe yaramadı.

İşte

da ben yapmaya çalışıyorum şeyin resmidir enter image description here

DÜZENLEME: İşte

Deniyordum RelativeLayout ile kod

<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"> 

    <RelativeLayout 
     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:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      android:background="#00000000"> 

      <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"/> 
    </android.support.design.widget.AppBarLayout> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <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.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" /> 
    </RelativeLayout> 

+0

"RelativeLayout" öğesini "CoordinatorLayout" içine koymaya çalıştığınız kod nerede? –

+0

2 yolu denedim. İlk önce, Koordinatörün tüm görüşlerini sardım, böylece Göreceli ilk ve tek çocuktu. Bu, tüm öğelerdeki kaydırma davranışının kaybedilmesine neden oldu. Ve diğeri de EDIT'de, Relatif'in içindeki RecyclerView ve bu arama kutusunu da sardım. –

+0

@NikolaMilutinovic Kaydırma davranışı, "CoordinatorLayout" öğesinin doğrudan alt öğesi olan tüm çocuklarda çalışır, dolayısıyla düzen davranışını "RelativeLepout" olarak ayarlarsanız, iç içe kaydırma işlemi çalışır. –

cevap

21

olduğunu Biraz benzer bir şey yapmak, ancak ekranın altındaki bir reklam banner ile. Benim çözümüm şekilde CoordinatorLayout dışında RelativeLayout sarmak için oldu: RecyclerView içine kaydırma yaparken

<?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> 

araç çubuğu düzgün gizler ve her şey iyi çalışıyor gibi görünüyor. Benzer bir ilkeyi izlediyseniz iyi gitmeniz gerektiğini düşünürdüm. Eğer durum çubuğu beyaz renk kaldırmak isterseniz

+0

Tam olarak neye ihtiyacım vardı (arama saatlerinden sonra!). Teşekkürler. – sidiabale

0

, örneğin v21/styles.xml

teşekkür sonraki satırı

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

kaldırmalısınız.

0
<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> 

Bunun sizin için uygun olup olmadığını kontrol edin.

İlgili konular