2016-07-30 21 views
0

Ich versuche ein Toolbar mit einem cardview ähnlich Google Play zu erstellen.Google Play Toolbar CardView

enter image description here

Wenn ich versuche, diese neu zu erstellen, wird die cardview haupt nicht angezeigt.

Hier ist ein Screenshot davon.

enter image description here

toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    card_view:cardCornerRadius="3dp" 
    card_view:cardElevation="3dp" 
    card_view:cardPreventCornerOverlap="false" 
    card_view:cardUseCompatPadding="true"> 

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

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


    </LinearLayout> 
</android.support.v7.widget.CardView> 

activity.xml

<android.support.design.widget.AppBarLayout 
    android:layout_marginRight="15dp" 
    android:layout_marginLeft="15dp" 
    android:layout_marginTop="15dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <include layout="@layout/toolbar"/> 

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

Bitte mir sagen, was falsch h ging ehe. Vielen Dank !

+1

denke ich, das ist eigentlich eine benutzerdefinierte Symbolleiste, dass Google Anwendungen spielen, kein CardView –

+0

Zum Beispiel, das Rad nicht neu erfinden. https://github.com/arimorty/floatingsearchview –

+0

Bitte überprüfen Sie diesen Code und versuchen Sie es mit Ihrem Code. http://android-pratap.blogspot.in/2014/12/recyclerview-with-onclick-and.html – mujjuraja

Antwort

1

Ändern Sie die Hintergrundfarbe von AppBarLayout in transparent. Und ich denke, es gibt unnötige Layout-Hierarchen.

Folgendes Layout funktioniert in meiner Umgebung.

toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:card_view="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     card_view:cardCornerRadius="3dp" 
     card_view:cardElevation="3dp" 
     card_view:cardPreventCornerOverlap="false" 
     card_view:cardUseCompatPadding="true"> 

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

</android.support.v7.widget.CardView> 

activity.xml:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:background="@android:color/transparent"> 

     <include layout="@layout/toolbar"/> 

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

</FrameLayout>