2014-11-16 65 views
1

請幫我創建Toolbar,哪些內容會超過@+id/left_drawer?可能嗎? enter image description hereAndroid導航繪圖器和工具欄

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

    <android.support.v7.widget.Toolbar 
     android:id="@+id/my_awesome_toolbar" 
     style="@style/MainTheme.ToolBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

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

      <com.astuetz.RobottoRegularTextView 
       android:id="@+id/toolbar_title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:textColor="@android:color/white" 
       android:textSize="20sp" /> 

      <com.astuetz.RobottoLightTextView 
       android:id="@+id/toolbar_subtitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:singleLine="true" 
       android:textColor="@android:color/white" 
       android:textSize="@dimen/small_text" 
       android:visibility="gone" /> 
     </LinearLayout> 
    </android.support.v7.widget.Toolbar> 

    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</LinearLayout> 

<!--ImageView for test --> 
<ImageView 
    android:id="@+id/left_drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:layout_marginTop="0dp" 
    android:layout_marginBottom="0dp" 
    android:scaleType="centerCrop" 
    android:adjustViewBounds="true" 
    android:src="@drawable/background" /> 

回答

1

@ hata非常接近正確的答案。 U需要在DrawerLayout後面加上Toolbar,使Toolbar的背景透明並在@+id/content_frame之前創建表格DrawerLayout,其高度將爲?attr/actionBarSize,背景顏色爲Toolbar。這裏是我的解決方案U

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

    <com.kpi.timetable.views.HackyDrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

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

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="@color/YOUR_ACTIONBAR_COLOR"/> 

      <FrameLayout 
       android:id="@+id/content_frame" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 
     </LinearLayout> 


     <ImageView 
      android:id="@+id/left_drawer" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:layout_marginBottom="0dp" 
      android:layout_marginTop="0dp" 
      android:adjustViewBounds="true" 
      android:scaleType="centerCrop" 
      android:src="@drawable/background" /> 
    </com.kpi.timetable.views.HackyDrawerLayout> 

    <!-- in your MainTheme.ToolBar style set background  --> 
    <!-- color to "@android:color/transparent" or set it here --> 
    <!-- as android:background="@android:color/transparent" --> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/my_awesome_toolbar" 
     style="@style/MainTheme.ToolBar"    
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize"> 

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

      <com.astuetz.RobottoRegularTextView 
       android:id="@+id/toolbar_title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:text="Расписание" 
       android:textColor="@android:color/white" 
       android:textSize="20sp" /> 

      <com.astuetz.RobottoLightTextView 
       android:id="@+id/toolbar_subtitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:singleLine="true" 
       android:textColor="@android:color/white" 
       android:textSize="@dimen/small_text" 
       android:visibility="gone" /> 
     </LinearLayout> 
    </android.support.v7.widget.Toolbar> 
</RelativeLayout> 
0

你在找什麼叫抽屜式導航欄。

我建議您訪問Android文檔

http://developer.android.com/training/implementing-navigation/nav-drawer.html

在這種情況下,你的代碼將

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/my_awesome_toolbar" 
     style="@style/MainTheme.ToolBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

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

      <com.astuetz.RobottoRegularTextView 
       android:id="@+id/toolbar_title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:textColor="@android:color/white" 
       android:textSize="20sp" /> 

      <com.astuetz.RobottoLightTextView 
       android:id="@+id/toolbar_subtitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:singleLine="true" 
       android:textColor="@android:color/white" 
       android:textSize="@dimen/small_text" 
       android:visibility="gone" /> 
     </LinearLayout> 
    </android.support.v7.widget.Toolbar> 

    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <LinearLayout android:id="@+id/left_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:background="#fff"/> 
</android.support.v4.widget.DrawerLayout> 
+0

這是一個簡單的抽屜實現。在我上傳的照片上打圈。有全屏高度菜單(在你的案例listView),其中後滑動來自左邊界和工具欄的內容是在它之上。也許工具欄的bg透明,但我不知道如何使它的內容在菜單上 – AskQuestion

1

父的LinearLayout裏面,工具欄可以放置在第一和DrawerLayout可能放在第二位。

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

    <android.support.v7.widget.Toolbar 
     android:id="@+id/my_awesome_toolbar" 
     style="@style/MainTheme.ToolBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

    (...) 

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

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <FrameLayout 
      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <fragment 
      android:id="@+id/left_drawer" 
      android:layout_width="@dimen/navigation_drawer_width" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      tools:layout="@layout/fragment_navigation_drawer" /> 

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

</LinearLayout>