
'java.lang.classCastException: androID.Widget.linearLayout$LayoutParams cannot be cast to androID.support.v4.Widget.DrawerLayout$LayoutParams'
错误.我不确定这是否可能是直接的方式,因为我检查了几个链接,我得到的唯一关闭是this.任何帮助表示赞赏.
提前致谢.
这是我的代码.
<!-- The main context vIEw --><FrameLayout androID:ID="@+ID/content_frame" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" /><!-- The navigation drawer --><linearLayout androID:layout_wIDth="240dp" androID:layout_height="match_parent" androID:layout_gravity="start" androID:background="#fff" androID:gravity="bottom|center" androID:orIEntation="vertical" androID:paddingtop="30dp" > <ListVIEw androID:ID="@+ID/left_drawer" androID:choiceMode="singleChoice" androID:divIDer="#E8E8E8" androID:divIDerHeight="1dp" androID:footerdivIDersEnabled="false" androID:headerdivIDersEnabled="false" /> <ImageVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_gravity="center" androID:padding="10dp" androID:src="@drawable/footer_image" /></linearLayout>
现在的问题是,xml不允许我为ListvIEw定义宽度和高度(Element未知),我也无法运行它,因为编译器说“你必须提供layout_wIDth”属性?请帮忙.
我的代码与scrollvIEw.
<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 context vIEw --><FrameLayout androID:ID="@+ID/content_frame" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" /><!-- The navigation drawer --><ScrollVIEw androID:ID="@+ID/leftRL" androID:layout_wIDth="240dp" androID:layout_height="match_parent" androID:layout_gravity="start" androID:layout_marginBottom="5dp" androID:background="#fff" > <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="vertical" > <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="vertical" androID:paddingleft="10dp" androID:paddingRight="10dp" androID:paddingtop="10dp" > <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:paddingBottom="3dp" androID:src="@drawable/ic_launcher" androID:text="Dummy" androID:textcolor="#2E3192" androID:textStyle="bold" /> <VIEw androID:layout_wIDth="fill_parent" androID:layout_height="2dip" androID:background="#2E3192" /> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal" androID:paddingtop="2dp" > <ImageVIEw androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:layout_weight="3" androID:background="#e8e8e8" androID:scaleType="fitXY" androID:src="@drawable/ic_launcher" /> <linearLayout androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:layout_weight="7" androID:gravity="center" androID:orIEntation="vertical" androID:padding="5dp" > <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:text="Dummy name" androID:textSize="15sp" /> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:text="dummyemail@imhot.com" androID:textSize="10sp" /> </linearLayout> </linearLayout> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_margintop="20dp" androID:paddingBottom="3dp" androID:src="@drawable/ic_launcher" androID:text="Dummy item" androID:textcolor="#2E3192" androID:textStyle="bold" /> <VIEw androID:layout_wIDth="fill_parent" androID:layout_height="2dip" androID:background="#2E3192" /> </linearLayout> <ListVIEw/> <ImageVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_gravity="center" androID:layout_margintop="40dp" androID:padding="10dp" androID:src="@drawable/footer_image" /> </linearLayout></ScrollVIEw></androID.support.v4.Widget.DrawerLayout>解决方法 如果没有代码,您的查询很难理解. stacktrace,但无论如何……
记住androID.support.v4.Widget.DrawerLayout只能有3个元素(按照这个顺序):
>您的主页
>左抽屉
>右抽屉
复制粘贴这个例子(只有前两个元素)&继续你的要求
<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" ><!-- Your main screen --><relativeLayout androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" > <relativeLayout androID:ID="@+ID/topRL" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:background="#DE6D53" androID:orIEntation="horizontal" > <Imagebutton androID:ID="@+ID/left_drawer_button" androID:layout_wIDth="30dp" androID:layout_height="30dp" androID:layout_alignParentleft="true" androID:layout_centerVertical="true" androID:gravity="center_vertical" androID:onClick="onopenleftDrawer" androID:src="@drawable/ic_launcher" /> </relativeLayout> <FrameLayout androID:ID="@+ID/frame_to_be_replaced" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_below="@+ID/topRL" /></relativeLayout><!-- left drawer --><relativeLayout androID:ID="@+ID/whatYouWantInleftDrawer" androID:layout_wIDth="290dp" androID:layout_height="match_parent" androID:layout_gravity="start" androID:background="@androID:color/black" > <TextVIEw androID:ID="@+ID/textVIEw" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:text="Title" androID:textcolor="@androID:color/white" /> <ListVIEw androID:ID="@+ID/left_expandableListVIEw" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_gravity="start" /> <TextVIEw androID:layout_wIDth="25dp" androID:layout_height="25dp" androID:layout_alignParentBottom="true" androID:textcolor="@androID:color/white" androID:text="bottom" /></relativeLayout></androID.support.v4.Widget.DrawerLayout>
你的活动:
public class MainActivity extends Activity {relativeLayout leftRL;relativeLayout rightRL;DrawerLayout drawerLayout; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);// I'm removing the Actionbar. requestwindowFeature(Window.FEATURE_NO_Title); setContentVIEw(R.layout.temp); leftRL = (relativeLayout)findVIEwByID(R.ID.whatYouWantInleftDrawer); drawerLayout = (DrawerLayout)findVIEwByID(R.ID.drawer_layout); } public voID onopenleftDrawer(VIEw vIEw) { drawerLayout.openDrawer(leftRL); }} 总结 以上是内存溢出为你收集整理的android – 向导航抽屉添加线性布局(最终崩溃与ClassCastException)全部内容,希望文章能够帮你解决android – 向导航抽屉添加线性布局(最终崩溃与ClassCastException)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)