1

私のactivity_mainにappbarを設定したいと思います。何らかの理由で、正しく設定できません。リサイクラービューの下に設定されています。RecyclerviewをAppbarの下に設定する

ここにここに私のactivity_main

<?xml version="1.0" encoding="utf-8"?> 
 

 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:id="@+id/drawer_layout" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:fitsSystemWindows="true" 
 
    tools:openDrawer="start"> 
 

 

 
    <include 
 
     layout="@layout/app_bar_main" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" /> 
 

 

 

 

 
    <RelativeLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:orientation = "vertical" 
 
     android:layout_marginTop="?attr/actionBarSize" 
 
     tools:context=".MainActivity"> 
 

 
     <android.support.v7.widget.RecyclerView 
 
      android:id="@+id/recyclerview_heritage_sites" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:scrollbars="vertical"/> 
 

 
    </RelativeLayout> 
 

 

 
</android.support.v4.widget.DrawerLayout>

は私app_bar_mainです

<?xml version="1.0" encoding="utf-8"?> 
 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    tools:context=".MainActivity"> 
 

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

 
     <android.support.v7.widget.Toolbar 
 
      android:id="@+id/toolbar" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="?attr/actionBarSize" 
 
      android:background="@color/colorWhite" 
 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 
 

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

 

 

 

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

あなたの時間と時間をありがとうエル・P!

答えて

1
<?xml version="1.0" encoding="utf-8"?> 

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <include 
      android:id="@+id/appbar" 
      layout="@layout/app_bar_main" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="?attr/actionBarSize" 
      android:layout_below="@id/appbar" 
      tools:context=".MainActivity"> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/recyclerview_heritage_sites" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:scrollbars="vertical"/> 

     </RelativeLayout> 
    </RelativeLayout> 


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

感謝を!それは働いている。私の実装はなぜ機能していませんでしたか? –

+0

レイアウトのために、LinearLayoutを使用する必要があるビューを垂直または水平に配置するか、またはRelativeLayout設定のlayout_belowなどを使用することができました。あなたのケースでは、LinearLayoutがAppBarLayoutおよびDrawerLayoutに対して機能しない可能性があります。答えを受け入れてください、ありがとう! – MarcGV

+0

意味があります。私は基本的なものを忘れていたに違いない。私の悪い! –

1

あなたはLinearLayoutを使用することができます。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

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

     <include 
      layout="@layout/app_bar_main" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation = "vertical" 
      android:layout_marginTop="?attr/actionBarSize" 
      tools:context=".MainActivity"> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/recyclerview_heritage_sites" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:scrollbars="vertical"/> 

     </RelativeLayout> 

    </LinearLayout> 

</android.support.v4.widget.DrawerLayout> 
+0

答えをありがとう。 Relativelayoutを使用して問題を修正しました。 –

+0

私の考えでは、「LinearLayout」はこの場合もっと簡単ですが、とにかく問題を修正してうれしいです。 –

+0

その後、 'android:layout_marginTop ="?attr/actionBarSize "'を削除する必要があります。追加する他のコンポーネントがあります。だから、私は外に相対レイアウトが必要です。 –

関連する問題