我想用子菜单做抽屉布局。但该子菜单应作为新布局加载。不是可扩展的列表视图或可扩展的回收站。
但是目前我已经隐藏了linearlayout来打开submeu,如下面的代码。
这是drawer_layout
int[] array1 = new int[] { 1, 2, 3, 4, 5 };
int[] array2 = new int[] { 1, 2, 3 };
List<Integer> output = new ArrayList<>();
for (int i = 0; i < array1.length; i++) {
boolean flag = false;
for (int j = 0; j < array2.length; j++) {
if (array1[i] == array2[j]) {
flag = true;
break;
}
}
if (!flag) {
output.add(array1[i]);
}
}
System.out.println(output);
这包括navigation_drawer布局。
<?xml version="1.0" encoding="utf-8"?>
<layout>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
</android.support.design.widget.CoordinatorLayout>
<include
android:id="@+id/includeLayoutDrawer"
layout="@layout/navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
在抽屉类中,我编写了隐藏线性布局的代码,并显示子菜单linearlayout,如下面的代码。
<?xml version="1.0" encoding="utf-8"?>
<layout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutDrawer"
android:layout_width="@dimen/width_menu"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:animateLayoutChanges="true"
android:background="@color/white"
android:orientation="vertical">
<!--profile-->
<LinearLayout
android:id="@+id/headerM"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/profPic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/gap_activity"
android:src="@drawable/img_menu_avator" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/gap_activity"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test"
android:textColor="@color/black"
android:textSize="18sp" />
<TextView
android:id="@+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/gap_small"
android:text="@string/distributor"
android:textColor="@color/darkGrey"
android:textSize="@dimen/normal" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="@dimen/width_menu"
android:layout_height="1dp"
android:background="@color/separator" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:scrollbars="none">
<!--menu items-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/gap_large">
<LinearLayout
android:id="@+id/menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<!--my property-->
<LinearLayout
android:id="@+id/home"
android:layout_width="match_parent"
android:layout_height="@dimen/height_menu_item"
android:background="@drawable/ic_menu_icon_sel"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/gap_large">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_menu_avator" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="@dimen/gap_activity"
android:text="@string/d_home"
android:textColor="@color/veryDarkGrey"
android:textSize="@dimen/normal" />
</LinearLayout>
<View
android:layout_width="@dimen/width_menu"
android:layout_height="1dp"
android:background="@color/separator" />
<!--connections-->
<LinearLayout
android:id="@+id/addNewWorkShop"
android:layout_width="match_parent"
android:layout_height="@dimen/height_menu_item"
android:background="@drawable/ic_menu_icon_sel"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/gap_large">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_menu_avator" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/gap_activity"
android:text="@string/d_addnew_workshop"
android:textColor="@color/darkGrey"
android:textSize="@dimen/normal" />
</LinearLayout>
<View
android:layout_width="@dimen/width_menu"
android:layout_height="1dp"
android:background="@color/separator" />
<!--message-->
<LinearLayout
android:id="@+id/myProfile"
android:layout_width="match_parent"
android:layout_height="@dimen/height_menu_item"
android:background="@drawable/ic_menu_icon_sel"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/gap_large">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_menu_avator" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/gap_activity"
android:text="@string/d_my_profile"
android:textColor="@color/darkGrey"
android:textSize="@dimen/normal" />
</LinearLayout>
<View
android:layout_width="@dimen/width_menu"
android:layout_height="1dp"
android:background="@color/separator" />
<!--alerts-->
<LinearLayout
android:id="@+id/myTarget"
android:layout_width="match_parent"
android:layout_height="@dimen/height_menu_item"
android:background="@drawable/ic_menu_icon_sel"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/gap_large">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_menu_avator" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/gap_activity"
android:text="@string/d_my_target"
android:textColor="@color/darkGrey"
android:textSize="@dimen/normal" />
</LinearLayout>
<View
android:layout_width="@dimen/width_menu"
android:layout_height="1dp"
android:background="@color/separator" />
</LinearLayout>
<LinearLayout
android:id="@+id/subMenu"
android:layout_width="@dimen/width_menu"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:animateLayoutChanges="true"
android:background="@color/white"
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:id="@+id/back"
android:layout_width="match_parent"
android:layout_height="@dimen/height_menu_item"
android:background="@drawable/ic_menu_icon_sel"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/gap_large">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_menu_avator" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/gap_activity"
android:text="Back"
android:textColor="@color/darkGrey"
android:textSize="@dimen/normal" />
</LinearLayout>
<View
android:layout_width="@dimen/width_menu"
android:layout_height="1dp"
android:background="@color/separator" />
<LinearLayout
android:id="@+id/test"
android:layout_width="match_parent"
android:layout_height="@dimen/height_menu_item"
android:layout_marginLeft="@dimen/activity"
android:background="@drawable/ic_menu_icon_sel"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/gap_large">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_menu_avator" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/gap_activity"
android:text="Back"
android:textColor="@color/darkGrey"
android:textSize="@dimen/normal" />
</LinearLayout>
<View
android:layout_width="@dimen/width_menu"
android:layout_height="1dp"
android:background="@color/separator" />
<LinearLayout
android:id="@+id/test1"
android:layout_width="match_parent"
android:layout_height="@dimen/height_menu_item"
android:layout_marginLeft="@dimen/activity"
android:background="@drawable/ic_menu_icon_sel"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/gap_large">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_menu_avator" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/gap_activity"
android:text="Back"
android:textColor="@color/darkGrey"
android:textSize="@dimen/normal" />
</LinearLayout>
<View
android:layout_width="@dimen/width_menu"
android:layout_height="1dp"
android:background="@color/separator" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout
但我需要打开子菜单, 当我单击抽屉菜单按钮时,抽屉将从左到右滑块打开。然后,如果我单击任何内容打开子菜单,则必须打开子菜单,如主抽屉打开。然后,如果我单击后退按钮,那么它应该返回主内容抽屉。
实际上我期待这样的壳牌投资者&amp;媒体应用抽屉。
谢谢