2015-10-14 26 views
0
採用抽屜式導航
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="none"> 
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="16dp" 
    android:gravity="center" 
    android:orientation="vertical"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/main_cardView01" 
     android:layout_alignRight="@+id/main_cardView01" 
     android:orientation="horizontal" 
     android:layout_gravity="top"> 
      <Button 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/main_button_script" 
     android:text="@string/script_btn" 
     android:layout_margin="5dp" 
     android:theme="@style/main_button" 
     android:background="@drawable/main_button_script" 
     android:layout_weight="1" 
     android:textAppearance="?android:attr/textAppearanceMedium"/> 
     <Button 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/main_button_addOn" 
     android:text="@string/addOn_btn" 
     android:layout_margin="5dp" 
     android:theme="@style/main_button" 
     android:background="@drawable/main_button_addon" 
     android:layout_weight="1" 
     android:textAppearance="?android:attr/textAppearanceMedium"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/main_cardView01" 
      android:layout_alignRight="@+id/main_cardView01" 
     android:orientation="horizontal"> 
      <Button 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/main_button_map" 
     android:text="@string/map_btn" 
     android:layout_margin="5dp" 
     android:theme="@style/main_button" 
     android:background="@drawable/main_button_map" 
     android:layout_weight="1" 
     android:textAppearance="?android:attr/textAppearanceMedium"/> 
     <Button 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/main_button_skin" 
     android:text="@string/skin_btn" 
     android:layout_margin="5dp" 
     android:theme="@style/main_button" 
     android:background="@drawable/main_button_skin" 
     android:layout_weight="1" 
     android:textAppearance="?android:attr/textAppearanceMedium"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/main_new_cardView" 
     android:layout_alignRight="@+id/main_new_cardView" 
     android:orientation="horizontal"> 
      <Button 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/main_button_texturePack" 
     android:text="@string/tp_btn" 
     android:layout_margin="5dp" 
     android:theme="@style/main_button" 
       android:background="@drawable/main_button_texturepack" 
     android:layout_weight="1" 
     android:textAppearance="?android:attr/textAppearanceMedium"/> 
     <Button 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/main_button_help" 
      android:text="@string/help_btn" 
      android:layout_margin="5dp" 
      android:theme="@style/main_button" 
      android:background="@drawable/main_button_help" 
      android:layout_weight="1" 
       android:textAppearance="?android:attr/textAppearanceMedium"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/main_top10_cardView" 
     android:layout_alignRight="@+id/main_top10_cardView" 
     android:orientation="vertical"> 
     <View 
     android:layout_width="match_parent" 
     android:layout_height="16dp"/> 
     <TextView 
     android:id="@+id/top10" 
     android:text="Top 10" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="5dp" 
     android:layout_marginLeft="5dp" 
     android:textColor="#7A7A7A" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:background="@drawable/text" 
      android:gravity="right"/> 
     </LinearLayout> 
    <android.support.v7.widget.CardView 
     android:id="@+id/main_top10_cardView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:cardCornerRadius="0dp" 
     app:cardElevation="2dp" 
     app:cardUseCompatPadding="true" 
     android:foreground="@drawable/cardview"> 
     <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:orientation="vertical"> 
      <ImageView 
      android:id="@+id/main_top10_imageView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:adjustViewBounds="true" /> 
      <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:textColor="#5E5E5E" 
      android:textAppearance="?android:attr/textAppearanceMedium"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:textColor="#7a7a7a" 
      android:textAppearance="?android:attr/textAppearanceSmall"/> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/main_new_cardView" 
     android:layout_alignRight="@+id/main_new_cardView" 
     android:orientation="vertical"> 
     <View 
     android:layout_width="match_parent" 
     android:layout_height="16dp"/> 
     <TextView 
     android:id="@+id/suggested" 
     android:text="Suggested" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="5dp" 
     android:layout_marginLeft="5dp" 
     android:textColor="#7A7A7A" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:background="@drawable/text" 
      android:gravity="right"/> 
     </LinearLayout> 
    <android.support.v7.widget.CardView 
     android:id="@+id/main_suggested_cardView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:cardCornerRadius="0dp" 
     app:cardElevation="2dp" 
     app:cardUseCompatPadding="true" 
     android:foreground="@drawable/cardview"> 
     <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:orientation="vertical"> 
      <ImageView 
      android:id="@+id/main_suggested_imageView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:adjustViewBounds="true" /> 
      <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/ID00010bREDSTONE" 
      android:textColor="#5E5E5E" 
      android:textAppearance="?android:attr/textAppearanceMedium"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/USER_redstone" 
      android:textColor="#7a7a7a" 
      android:textAppearance="?android:attr/textAppearanceSmall"/> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/main_new_cardView" 
     android:layout_alignRight="@+id/main_new_cardView" 
     android:orientation="vertical"> 
     <View 
     android:layout_width="match_parent" 
     android:layout_height="16dp"/> 
     <TextView 
     android:id="@+id/New" 
     android:text="New" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="5dp" 
     android:layout_marginLeft="5dp" 
     android:textColor="#7A7A7A" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:background="@drawable/text" 
      android:gravity="right"/> 
     </LinearLayout> 
     <android.support.v7.widget.CardView 
     android:id="@+id/main_new_cardView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:cardCornerRadius="0dp" 
     app:cardElevation="2dp" 
     app:cardUseCompatPadding="true" 
     android:foreground="@drawable/cardview"> 
     <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:orientation="vertical"> 
      <ImageView 
      android:id="@+id/main_new_imageView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:adjustViewBounds="true" /> 
      <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:textColor="#5E5E5E" 
      android:textAppearance="?android:attr/textAppearanceMedium"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:textColor="#7a7a7a" 
      android:textAppearance="?android:attr/textAppearanceSmall"/> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 
    <LinearLayout 
     android:id="@+id/main_relativeLayout03" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/main_CS_cardView" 
     android:layout_alignRight="@+id/main_CS_cardView" 
     android:orientation="vertical"> 
     <View 
     android:layout_width="match_parent" 
     android:layout_height="16dp"/> 
     <TextView 
     android:id="@+id/CS" 
     android:text="Coming Soon" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="5dp" 
     android:layout_marginLeft="5dp" 
     android:textColor="#7A7A7A" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:background="@drawable/text" 
      android:gravity="right"/> 
     </LinearLayout> 
    <android.support.v7.widget.CardView 
     android:id="@+id/main_CS_cardView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:cardCornerRadius="0dp" 
     app:cardElevation="2dp" 
     app:cardUseCompatPadding="true" 
     android:foreground="@drawable/cardview"> 
     <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:orientation="vertical"> 
      <ImageView 
      android:id="@+id/main_CS_imageView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:adjustViewBounds="true" /> 
      <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:textColor="#5E5E5E" 
      android:textAppearance="?android:attr/textAppearanceMedium"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:textColor="#7a7a7a" 
      android:textAppearance="?android:attr/textAppearanceSmall"/> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/main_new_cardView" 
     android:layout_alignRight="@+id/main_new_cardView" 
     android:orientation="vertical"> 
     <View 
     android:layout_width="match_parent" 
     android:layout_height="16dp"/> 
     <TextView 
     android:id="@+id/updated" 
     android:text="Updated" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="5dp" 
     android:layout_marginLeft="5dp" 
     android:textColor="#7A7A7A" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:background="@drawable/text" 
      android:gravity="right"/> 
     </LinearLayout> 
    <android.support.v7.widget.CardView 
     android:id="@+id/main_updated_cardView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:cardCornerRadius="0dp" 
     app:cardElevation="2dp" 
     app:cardUseCompatPadding="true" 
     android:foreground="@drawable/cardview"> 
     <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:orientation="vertical"> 
      <ImageView 
      android:id="@+id/main_updated_imageView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:adjustViewBounds="true" /> 
      <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:textColor="#5E5E5E" 
      android:textAppearance="?android:attr/textAppearanceMedium"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:textColor="#7a7a7a" 
      android:textAppearance="?android:attr/textAppearanceSmall"/> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 
    </LinearLayout> 
</ScrollView> 

,滾動型

<android.support.v4.widget.DrawerLayout 
android:id="@+id/drawer" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:clickable="true"> 
<FrameLayout 
    android:id="@+id/drawer_layout" 
    android:layout_width="320dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start"> 
    <TextView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center|center" 
    android:text="test"/> 
</FrameLayout> 
</android.support.v4.widget.DrawerLayout> 

我要添加抽屜式導航在我的項目。我的源代碼看起來像第一個,第二個是導航抽屜,但是當我嘗試添加導航抽屜時,無論是導航抽屜出現,還是隻出現scrollview。

但是我要的是使用抽屜式導航和滾動型在一起(不滾動視圖內部抽屜式導航)

+0

我不明白你想要什麼。請給我更多的信息。 – aldakur

+0

我只是想在ScrollView內使用Navigation Drawer或類似的東西。當我嘗試將它們一起使用時,無論是僅導航抽屜出現或僅scroolview顯示 – Krim

+0

NavigationDrawer和滾動視圖可以工作,但在滾動視圖中的導航抽屜是不可能的(並且對我來說並沒有真正的感覺) – Xyaren

回答

0

使用導航抽屜爲您的活動根視圖的直接孩子做並添加另一個片段或佈局自己的代碼(滾動視圖)。同時,它的任務是在使用導航欄時,根視圖應該只包含兩個直接視圖。

+0

MainActivity {LinearLayout(RootView){DrawerLayout(NavigationDrawer){} LinearLayout {ScrollView {}}}}只有導航抽屜出現(當導航抽屜被移除時,滾動視圖會再次出現 – Krim

+0

試試這個並參考谷歌文檔。 <! - 主要內容視圖 - ><! id =「@ + id/left_drawer」android:layout_width =「240dp」android:layout_height =「match_parent」android:layout_gravity =「start」 –

+0

是不是在導航抽屜中使用scrollView? – Krim