我正在尝试在我的使用this教程的活动中放一个可滑动的抽屉。我的应用是针对Android 2.1-update1 (API 7)的。当我像这样创建xml布局时:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<SlidingDrawer
android:id="@+id/slidingDrawer"
android:handle="@+id/drawerHandle"
android:content="@+id/contentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center">
<EditText android:text="" android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="100px"/>
<Spinner android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:prompt="@string/strFilter" />
<Button android:text="Filtriraj" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
</SlidingDrawer>
<ScrollView android:layout_height="fill_parent" android:layout_width="fill_parent">
<TableLayout android:layout_width="fill_parent" android:id="@+id/tableLayout1" android:layout_height="fill_parent" android:orientation="horizontal">
<TableRow android:id="@+id/tableRow1" android:layout_height="wrap_content" android:baselineAligned="true" android:layout_gravity="center_horizontal" android:clipChildren="true" android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_margin="3dip">
<TextView android:clickable="true" android:layout_height="wrap_content" android:text="@string/lblOd" android:id="@+id/textView1" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:layout_marginRight="5dip"></TextView>
<TextView android:clickable="true" android:layout_height="wrap_content" android:id="@+id/textView2" android:text="@string/lblDatum" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:drawableLeft="@drawable/arrowdown"></TextView>
<TextView android:clickable="true" android:layout_height="wrap_content" android:id="@+id/textView3" android:text="@string/lblTekst" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:layout_marginLeft="3dip"></TextView>
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>当切换到“设计视图”-图形布局时,我得到了一个异常。错误是
ClassCastException: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be found: - SlidingDrawer我的代码出了什么问题?
发布于 2011-05-23 04:25:57
将设计视图切换到Android3.0,然后它就可以工作了,这是ADT中的某种bug。如果你在模拟器中运行它,那么代码就可以工作。
发布于 2012-01-03 09:38:47
不幸的是,当你的应用程序运行在数百万台2.x设备上时,你将会设计/布局3.0版本的东西。
发布于 2012-02-02 05:31:19
完全限定SlidingDrawer类名(android.widget.SlidingDrawer)为我解决了这个问题。然而,这似乎只适用于2.1-update1和更高版本。
此外,请确保将抽屉句柄设置为抽屉的有效子级。
https://stackoverflow.com/questions/6011529
复制相似问题