【发布时间】:2014-11-07 19:20:08
【问题描述】:
抽屉布局使用两个Relative Layout,报错为:
xml 文件:
<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" >
<!-- Listview to display slider menu -->
<RelativeLayout
android:id="@+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start" >
<ExpandableListView
android:id="@+id/list_slidermenu"
android:layout_width="197.50dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:background="#2f2f2f"
android:choiceMode="singleChoice"
android:divider="@drawable/divider"
android:dividerHeight="0.5dp"
android:groupIndicator="@android:color/transparent"
android:listSelector="#2FB3E3" />
<RelativeLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<TextView
android:id="@+id/build"
style="?android:textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingRight="100dp"
android:text="My View"
android:textColor="#FFFFFF" />
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
02-18 09:22:53.649: E/AndroidRuntime(30768): java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams 不能转换为 android.support.v4.widget.DrawerLayout$LayoutParams
public boolean onPrepareOptionsMenu(Menu menu) {
// if nav drawer is opened, hide the action items
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
if () {
--------
} else {
--------
}
return super.onPrepareOptionsMenu(menu);
}
它会抛出错误,因为“InvocationTargetException”行是
布尔抽屉打开=mDrawerlayout
【问题讨论】:
-
导入错误,请使用正确的导入。
-
现在检查是否也粘贴了 xml 代码,什么样的正确导入
-
看,您尝试将
RelativeLayout的布局参数放到DrawerLayout代码中的某个位置,因此请更正此 -
在 DrawerLayout 中,我希望 textview 在底部
-
但是你的
DrawerLayout在哪里
标签: android android-layout android-intent android-fragments