Yarh
Yarh

Reputation: 4607

Add image ABOVE item list in navigation drawer

I am trying to add image above itemss in navigation drawer to represent avatar. Following layout gaves me class cast exception as framelayout cannot be casted to drawer layout.

<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>

What will be a work around?

error

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)

Upvotes: 1

Views: 2344

Answers (1)

Larry Schiefer
Larry Schiefer

Reputation: 15775

Move the layout_gravity=start up to the FrameLayout tag which is the container of the ListView where you currently have it assigned (id = drawer_frame). The start gravity attribute value is special for the DrawerLayout and is meant for the top level container of the sliding drawer on the left.

Upvotes: 1

Related Questions