2012-08-09 48 views
0

我有這個問題2天,我找不到任何解決方案。listview和slidingdrawer給出錯誤

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/RelativeLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<ListView 
    android:id="@+id/presentation_list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
</ListView> 

<SlidingDrawer 
    android:id="@+id/slidingDrawer1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@id/presentation_list" 
    android:content="@+id/content" 
    android:handle="@+id/handle" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/handle" 
     android:layout_width="40dp" 
     android:layout_height="fill_parent" 
     android:background="@android:color/darker_gray" /> 

    <LinearLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/content_imageview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/black" /> 
    </LinearLayout> 
</SlidingDrawer> 

我有這個非常簡單的佈局,listviewslidingdrawer,我要過來了listview。當我打開我的activity沒有任何信息,它顯示完美,沒有任何例外。

但是當我的listview中有一個項目時,我的slidingdrawer給出了一種例外。

AndroidRuntime(4722): java.lang.RuntimeException: SlidingDrawer cannot have UNSPECIFIED dimensions 

我搜索了很多次的一個解決方案,但對我來說都不奏效。

有沒有人對我有着輝煌的突破?這是非常讚賞!

+0

我的佈局現在運行,更新我的問題以匹配佈局。 – Robin 2012-08-09 10:40:17

回答

-1

我認爲你必須在LinearLayout裏面定義SlidingDrawer而不是其他的方式。

+0

沒有,不是那個,linearlayout代表我滑動drawer的內容。 – Robin 2012-08-09 10:19:32

0

只是想到這個....如果你爲滑動抽屜裏面的content_imageview定義精確的尺寸會發生什麼。

查看您的代碼和Android文檔http://developer.android.com/reference/android/widget/SlidingDrawer.html這似乎是唯一的區別。

爲了更好地理解UNSPECIFIED以及如何在MeasureSpec中使用它,可能需要閱讀http://developer.android.com/reference/android/view/View.html

另請參閱指定手柄組件的設置尺寸。

關於你已經定義的佈局,你最好指定滑動抽屜alignParentBottom和對齊滑動抽屜上方的列表視圖。在一個簡短的清單中,你的滑動抽屜將坐在佈局的一半...

0

給你的android:layout_height相對佈局的一個數字(例如600 dip)。當滑動抽屜佈局高度爲match_parent時,它將沿着佈局高度爲fill_parent的相對佈局,這將導致您的滑動抽屜無限。