2011-05-15 55 views
1

我试图用this教程将滑动抽屉放到我的活动中。我的应用程序适用于Android 2.1-update1(API 7)。当我创建一个XML布局是这样的:Android SlidingDrawer

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

我的代码有什么问题?

回答

0

将设计视图切换到Android 3.0,然后它工作,ADT中的一些错误。如果你在模拟器中运行它,那么代码就可以工作。

0

不幸的是,当您的应用程序将运行在数百万的2.x设备上时,您将为3.0设计/布局事物。

0

完全限定SlidingDrawer类名(android.widget.SlidingDrawer)为我解决了这个问题。但是,这似乎只适用于2.1-update1及更高版本。

此外,请确保将抽屉手柄设置为抽屉的有效孩子。