2016-07-30 4 views
0

cardviewGoogle PlayのようなToolbarを作成しようとしています。私はこれを再作成しようとするとGoogle PlayツールバーCardView

enter image description here

、cardviewはまったく表示されません。

ここにそのスクリーンショットがあります。

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

activity.xml

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> 

間違った時間を行ったものを私に教えてくださいere。ありがとう!

+1

私はそれが実際にGoogleの用途を再生することをカスタムツールバーだと思う、ないCardView –

+0

は、例えば、車輪の再発明をしないでください。 https://github.com/arimorty/floatingsearchview –

+0

このコードを確認してコードを設定してみてください。 http://android-pratap.blogspot.in/2014/12/recyclerview-with-onclick-and.html – mujjuraja

答えて

1

AppBarLayoutの背景色を透明に変更します。 そして、私は不必要なレイアウトのヒエラルリーがあると思います。

次のレイアウトは私の感想の中で動作します。

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> 
関連する問題