0

AppCompatActivityを使用していますが、現時点ではツールバーにナビゲーションドロワーを追加しようとしています。CardViewなどの要素がxmlファイルに表示されない

問題は、カードビューが表示されず、ナビゲーションドロワーも機能していないことです。

これは私のコードです:誰かが私のエラーをしてください修正することができれば

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="150dp"> 

    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/cards" 
     android:layout_gravity="center" 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     card_view:cardCornerRadius="4dp"> 
     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:padding="10dp" 
      android:layout_alignParentBottom="true"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Username" 
       android:id="@+id/usersName" 
       android:layout_alignParentTop="true" 
       android:layout_alignParentStart="true" 
       android:layout_alignParentEnd="true" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Others" 
       android:id="@+id/others" 
       android:layout_centerVertical="true" 
       android:layout_alignParentStart="true" /> 

     </RelativeLayout> 
    </android.support.v7.widget.CardView> 
    <android.support.design.widget.NavigationView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent"></android.support.design.widget.NavigationView> 
</android.support.v4.widget.DrawerLayout> 

は本当に多くのことを意味し、私の一日になるだろう。私はどこに間違っているのか分からず、ツールバーのナビゲーションドロワボタンと画面上のカードビューを持っていたいだけです。

答えて

0

150dpのコンテナの中に200dpのカードビューを押し込もうとしています。 drawerlayoutにはmatch_parentを使用します。 次に、開発者ガイドから直接

XMLの順序がzオーダーを意味し、引き出しがコンテンツの上になければならないため、メインのコンテンツビューはDrawerLayoutの最初の子でなければなりません。

メインのコンテンツビューは、親ビューの幅と高さに一致するように設定されています。これは、ナビゲーションドロワーが非表示のときにUI全体を表すためです。

For more information follow the developer resources

0

これはandroid:layout_gravity="start"でNavigationViewとCardView android:layout_height="match_parent"や他のいくつかのマイナーな変更があり、このソリューションをお試しください。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="150dp"> 

    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/cards" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     card_view:cardCornerRadius="4dp"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentBottom="true" 
      android:padding="15dp"> 

      <TextView 
       android:id="@+id/usersName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:text="Username" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 

      <TextView 
       android:id="@+id/others" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:text="Others" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

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

    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="end" 
     android:fitsSystemWindows="true"> 

    </android.support.design.widget.NavigationView> 
</android.support.v4.widget.DrawerLayout> 
+1

非常に有用なコメントです。私は自分の答えを編集しました。@ MikeM。 –

+0

あなたの問題は解決していますか?@コードマン –

関連する問題