2012-08-13 54 views
0

我有一個視圖的XML佈局,表示一個ExpandableListAdapter顯示的項目(對於每個列表項目而不是主要活動佈局重複一次的XML)。我最初嘗試了一個LinearLayout,但是這隱藏了三個小部件(一個圖像按鈕)的最後一個。我明白爲什麼這樣做不起作用,但是我嘗試了RelativeLayout,但文本視圖不顯示。相關的佈局第一次連同一個截圖,還附加了我的初始佈局和屏幕截圖底部FWIW。謝謝你的幫助。Android ExpandableListAdapter視圖佈局不按要求顯示:-(

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="55dip" 
    android:orientation="horizontal" > 
    <CheckBox 
     android:id="@+id/chkParent" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:checked="false"/> 
    <EditText 
     android:id="@+id/edtParent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/chkParent" 
     android:textSize="17dip" 
     android:inputType="text" 
     android:hint="@string/strItem"/> 
    <ImageButton 
     android:id="@+id/btnExpand" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_toLeftOf="@id/edtParent" 
     android:src="@drawable/dark_expand" 
     android:clickable="true" 
     android:hint="@string/strViewSubItems" 
     android:contentDescription="@string/strViewSubItems" 
     android:background="@null"/> 
</RelativeLayout> 

screenshot for relative layout

原線佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="55dip" 
    android:orientation="horizontal" > 
    <CheckBox 
     android:id="@+id/chkParent" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:checked="false"/> 
    <EditText 
     android:id="@+id/edtParent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textSize="17dip" 
     android:inputType="text" 
     android:hint="@string/strItem"/> 
    <ImageButton 
     android:id="@+id/btnExpand" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:src="@drawable/dark_expand" 
     android:clickable="true" 
     android:hint="@string/strViewSubItems" 
     android:contentDescription="@string/strViewSubItems" 
     android:background="@null"/> 
</LinearLayout> 

screenshot for linear layout

回答

1

很肯定你toLeftOf屬性應該是toRightOf屬性。試一試,看看會發生什麼。

其實,你的EditText應該設置爲toRightOf="@id/chkParent"toLeftOf="@id/btnExpand。您的ImageButton甚至不需要toRightOf修飾符,alignParentRight屬性應該覆蓋它。

+0

Doh ...這是toLeftOf上的一個大腦放屁,當我發佈它時,我再次將它放回...但是是的,編輯文本的左右兩邊都有固定的屬性......這讓我把圖像按鈕作爲第二個元素,最後編輯,因爲我猜測編譯器只顯示一個XML傳遞? – 2012-08-13 20:30:20

+0

啊,有一種解決方法,只要在XML中引用另一個時使用'@ + id /'而不是'@ id /',並且您可以保持它的順序。基本上,只是在第一次引用XML中的ID時使用「+」,無論您是設置ID還是僅指它。 – kcoppock 2012-08-13 20:33:52

+1

哦,很好!很高興知道。感謝您一如既往的幫助兄弟! :-) – 2012-08-13 21:29:38