CQM*_*CQM 1 android android-listview navigation-drawer
我正在使用ActionsContentView库作为侧面菜单栏.
https://play.google.com/store/apps/details?id=sample.actionscontentview
最初我尝试在支持库中使用Google的NavigationDrawer对象.但是我放弃了它,因为我需要一个非listview类型的布局用于视图的某些部分.
无论如何,我想知道这个推理是否有缺陷.我的菜单的一部分是使用非列表视图和一些相当复杂的自定义布局,可以在滚动视图中动态添加,或者最终可能最终成为列表视图中的自定义适配器.
无论如何,我需要ActionsContentView库已经提供的灵活性
我可以在NavigationDrawer中使用非列表视图吗?
您可以.
DrawerLayout是一个包含2个布局的布局 - 1是菜单,另一个是内容.
这意味着您可以在菜单抽屉中放置一个片段,并使用您想要的任何内容填充该片段.
<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">
<FrameLayout
android:id="@+id/activityFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<FrameLayout
android:id="@+id/drawer"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/backgound_menu" >
<fragment
android:id="@+id/menuFragment"
android:name="com.foo.bar.fragment.MenuFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/menu_fragment" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
您可以通过菜单活动扩展的基本活动类来完成此操作.然后在基本活动中添加setFrameContent方法,该方法将使用内容片段填充活动框架.在您的子类中,在onCreate方法中调用setFrameContent而不是setConentView.
基础活动
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_fragment_drawer);
}
public void setFrameContent(int activityLayout) {
mContent.addView(
getLayoutInflater().inflate(
activityLayout,
mContent, false),
new LinearLayout.LayoutParams(DrawerLayout.LayoutParams.MATCH_PARENT,
DrawerLayout.LayoutParams.MATCH_PARENT));
}
Run Code Online (Sandbox Code Playgroud)
子类
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_fragment_content);
}
Run Code Online (Sandbox Code Playgroud)
从那里你可以自由地使用MenuFragment做任何事情.
| 归档时间: |
|
| 查看次数: |
2253 次 |
| 最近记录: |