【发布时间】:2016-10-14 16:14:48
【问题描述】:
我想将我的导航抽屉片段添加到活动中,但我希望导航抽屉“后面”的活动布局保持不变。
导航抽屉片段活动 XML
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:id="@+id/drawerPane"
android:layout_gravity="start">
<RelativeLayout
android:id="@+id/logoBox"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/material_blue_grey_800"
android:padding="8dp" >
<ImageView
android:id="@+id/g4aLogo"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
<ListView
android:id="@+id/settingsList"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_below="@+id/logoBox"
android:choiceMode="singleChoice"
android:background="#ffffffff" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
活动 XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activity_main"
android:orientation="vertical"
android:weightSum="10">
<LinearLayout
android:layout_weight="1"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/searchBarLay"
android:focusable="true"
android:focusableInTouchMode="true">
//CONTENTS and layouts...
</LinearLayout>
</LinearLayout>
实现导航抽屉时的活动代码部分
private void initSettingsDrawer() {
Button settingsDrawerButton =(Button)findViewById(R.id.settingsDrawer);
settingsDrawerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SettingsDrawer settingsDrawer = new SettingsDrawer();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().add(R.id.activity_main, settingsDrawer).commit();
}
});
}
【问题讨论】:
标签: android android-fragments navigation-drawer