我正在尝试在导航抽屉中的itemss上添加图像来表示头像。 以下布局为我提供了类转换异常,因为framelayout无法转换为抽屉布局。
<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"
android:layout_alignParentLeft="true" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include
android:id="@+id/loader"
layout="@layout/loading_view" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</FrameLayout>
<FrameLayout
android:id="@+id/drawer_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/im_avatar"
android:layout_width="200dip"
android:layout_height="200dip"
android:background="#000000" />
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
什么是解决方法?
错误
08-05 12:29:22.666: E/AndroidRuntime(10442): FATAL EXCEPTION: main
08-05 12:29:22.666: E/AndroidRuntime(10442): Process: bigdig.yarh.ellotv.activitytry, PID: 10442
08-05 12:29:22.666: E/AndroidRuntime(10442): java.lang.RuntimeException: Unable to start activity ComponentInfo{bigdig.yarh.ellotv.activitytry/bigdig.yarh.ellotv.activitytry.MainFeedActivity}: java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.app.ActivityThread.access$800(ActivityThread.java:156)
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.os.Handler.dispatchMessage(Handler.java:102)
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.os.Looper.loop(Looper.java:157)
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.app.ActivityThread.main(ActivityThread.java:5872)
08-05 12:29:22.666: E/AndroidRuntime(10442): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 12:29:22.666: E/AndroidRuntime(10442): at java.lang.reflect.Method.invoke(Method.java:515)
08-05 12:29:22.666: E/AndroidRuntime(10442): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
08-05 12:29:22.666: E/AndroidRuntime(10442): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
08-05 12:29:22.666: E/AndroidRuntime(10442): at dalvik.system.NativeStart.main(Native Method)
08-05 12:29:22.666: E/AndroidRuntime(10442): Caused by: java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:968)
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.support.v4.widget.DrawerLayout.openDrawer(DrawerLayout.java:1129)
08-05 12:29:22.666: E/AndroidRuntime(10442): at bigdig.yarh.ellotv.activitytry.MainFeedActivity.onCreate(MainFeedActivity.java:42)
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.app.Activity.performCreate(Activity.java:5312)
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
08-05 12:29:22.666: E/AndroidRuntime(10442): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552)
答案 0 :(得分:1)
将layout_gravity=start
向上移动到FrameLayout
标记,该标记是您当前为其指定的ListView
的容器(id = drawer_frame
)。 start
重力属性值对于DrawerLayout
是特殊的,适用于左侧滑动抽屉的顶级容器。