朋友们我是android的新手..。
场景我在应用程序中使用drawerLayout来使用滑块菜单.但是,正如一般android开发人员指南中所描述的,我不想根据滑块菜单视图中的单击更改content_frame .但是content_frame将保持不变,只有信息将是changing..so,它将基于在滑块菜单中选择的操作更新的数据。
现在正在发生的事情:,我使用相同的示例,使用下面的代码(1),并将文件中的主视图布局定义为content_frame.xml,但它不起作用,我得到了一个空白窗口.相反,我将相同的布局定义到相同的FrameLayout中,如下面的代码(2)所示,但是我无法正确地排列其中的组件。我可以从不同的地方看到,因为这是一个肮脏的编码方法.
我需要做的事情,,我需要将我的主视图的布局文件链接到这个frameLayout,这样我就可以在我的应用程序中使用DrawerLayout和滑块菜单。
请帮助我在android系统中实现这一目标。
谢谢你的时间和努力..。
(1)开发人员指南的示例代码
<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">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>(2)我的代码
<?xml version="1.0" encoding="utf-8"?>
<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">
<!-- The main content view -->
<FrameLayout
android:id="@+id/r1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ListView
android:id="@+id/lv1"
android:layout_width="match_parent"
android:layout_height="200dp"
/>
<CalendarView
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="400dp"
/>
</FrameLayout>
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#fff"/>
</android.support.v4.widget.DrawerLayout>发布于 2014-04-23 08:35:23
如果我正确理解,您希望为您的内容和抽屉都有一个布局文件,并且您不会为您的内容使用片段。
要实现这一点,您只需将内容的布局定义为DrawerLayout视图的第一个子视图,将抽屉的布局定义为第二个,就像在示例中所做的那样。
问题是,这些视图不必是FrameLayout和ListView,在示例中,它们可以是您想要的任何内容。
例如:
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewContent"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/dl_left_drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="left">
<TextView
android:id="@+id/left_drawer_TextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/left_drawer_TextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ListView android:id="@+id/dl_left_drawer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout></android.support.v4.widget.DrawerLayout>在这里,你可以看到内容和抽屉都是线性布局,尽管它们可以是你想要的任何东西。
编辑
如果将主内容视图包含在单独的文件(例如main_content.xml)中,还可以使用<include layout="@layout/main_content"/>而不是第一个<LinearLayout >.... </LinearLayout>。
欲了解更多信息:http://developer.android.com/training/improving-layouts/reusing-layouts.html
https://stackoverflow.com/questions/23238277
复制相似问题