1

내 activity_main에 appbar를 설정하고 싶습니다. 웬일인지, 나는 그것을 올바르게 설정할 수 없다. 리사이클 러 뷰 아래에 설정됩니다. 여기 아래의 Recyclerview 설정하기

내 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>
당신의 시간과 시간 주셔서 감사입니다 엘프!

답변

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"'를 제거해야합니다. 추가 할 다른 구성 요소가 있습니다. 그래서, 저는 상대적인 레이아웃이 필요합니다. –