簡體   English   中英

Android:直接導入SlidingDrawer源代碼后收到IllegalArgumentException

[英]Android: receiving IllegalArgumentException after directly importing SlidingDrawer source code

從Android SDK復制SlidingDrawer代碼並將其導入到我的項目中時,我得到了一個IAE。

java.lang.IllegalArgumentException:handle屬性是必需的,並且必須引用一個有效的子級。

這是我的布局文件:

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MySlidingDrawer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="test only"
        android:textSize="20dp" />

    <com.mytest.view.SlidingDrawer
        android:id="@+id/SlidingDrawer"
        android:layout_width="wrap_content"
        android:layout_height="250dip"
        android:layout_alignParentBottom="true"
        android:content="@+id/contentLayout"
        android:handle="@+id/slideButton"
        android:orientation="vertical"
        android:topOffset="100.5dp"
        android:padding="10dip" >

        <Button
            android:id="@id/slideButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="UP" >
        </Button>

        <LinearLayout
            android:id="@id/contentLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="10dip" >

            <Button
                android:id="@+id/Button01"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="2dp"
                android:text="Button01" >
            </Button>
        </LinearLayout>
    </com.mytest.view.SlidingDrawer>

</RelativeLayout>

這是我的attrs:

  <declare-styleable name="SlidingDrawer"> 
        <attr name = "orientation"  format="integer"/>
        <attr name = "bottomOffset" format = "dimension"/>
        <attr name = "topOffset" format = "dimension"/>
        <attr name = "allowSingleTap" format = "boolean"/>
        <attr name = "animateOnClick" format = "boolean"/>
        <attr name = "handle" format = "reference"/>
        <attr name = "content" format = "reference"/>
    </declare-styleable>

好的,這是一個問題,所以這不是您的問題。

http://code.google.com/p/android/issues/detail?id=3162

我認為這就是在API級別17棄用滑動抽屜的原因。

編輯:

在您的按鈕上,嘗試將android:id="@id/slideButton"更改為android:id="@+id/slideButton"

用作滑動抽屜句柄的View必須具有android:id =“ @ id / handle”才能使SlidingDrawer工作

檢查此鏈接。 我認為您必須聲明自己的名稱空間才能引用處理程序http://chrisharrington1.wordpress.com/2012/02/06/android-modifying-the-slidingdrawer-widget-to-use-a-max-height/

您的問題是您將類作為自定義視圖導入,但仍然使用:

android:content="@+id/contentLayout"
android:handle="@+id/slideButton"

使用此代替:

app:content="@+id/contentLayout"
app:handle="@+id/slideButton"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM