【发布时间】:2015-04-24 13:07:38
【问题描述】:
我是 Android 新手,我正在实现一个导航抽屉,到目前为止,我已经设法在抽屉中列出我的项目,并在我的框架布局中添加了一个片段。 主页正常工作,但是当我打开抽屉时,我的 FrameLayout 中的按钮出现在导航抽屉的上方。
我需要让框架布局出现在导航抽屉下方。
我的代码如下
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.shimplyapp.MainActivity" >
<fragment
android:id="@+id/navigation_drawer"
android:name="com.example.shimplyapp.NavigationDrawerFragment"
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>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</FrameLayout>
</RelativeLayout>
fragment_navigation_drawer.xml
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@android:color/black"
tools:context="com.example.shimplyapp.NavigationDrawerFragment" />
home_default.xml
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:gravity="center"
android:orientation="vertical" >
<EditText
android:id="@+id/etxt_sn_enter_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:hint="enter_search_ item here.."
android:inputType="text"
android:maxLength="15"
android:singleLine="true" />
<Button
android:id="@+id/btn_lm_search_number"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="15dp"
android:text="search"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/btn_lm_view_stores"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="15dp"
android:text="store"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/btn_lm_view_deals"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="15dp"
android:text="deal"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
这是我从 MainActivity
调用的片段@Override
public void onNavigationDrawerItemSelected(int position) {
Fragment fragment = null;
FragmentManager fragmentManager;
//flag a global variable initially flag = 0;
if(flag ==0){
fragment = new HomePage();
fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();
flag = 1;
}
//..... rest is switch cases for calling different fragments
}
【问题讨论】:
-
将框架布局放在 xml 中的导航抽屉上方
标签: android navigation-drawer android-framelayout