我有一個ListView和在其行,每一行觀點我已經使用了以下佈局:爲什麼當ListView的高度設置爲wrap_content時,其行爲與預期不符?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView_contactPhoto"
android:tag="contact_photo"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:contentDescription="@string/contentDescription_contactPhoto" />
<ImageView
android:id="@+id/imageView_contactConversationSymbol"
android:tag="contact_symbol"
android:src="@drawable/they_said"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_above="@+id/imageView_contactPhoto"
android:layout_toLeftOf="@+id/imageView_contactPhoto"
android:contentDescription="@string/contentDescription_contactPhoto" />
但我只能看到每一行的第一個形象,如果第二個不存在在所有。但是,當我將ListView的高度設置爲特定值時,如:
android:layout_height="192dp"
這兩個圖像都存在。任何想法?
編輯 這就是我想要實現:
你可以嘗試使用'LinearLayout'代替'RelativeLayout' – Rick
的檢查RelativeLayout的文檔。你不能有alignParentBottom和wrap_content的高度 - 這是沒有道理的。既然你正在設置每個元素的高度和寬度,爲什麼不爲它設置一個靜態高度呢?或者更好,請按照上面評論和用戶LinearLayout中的建議,它完全符合你的目標。 – 323go
另外,請勿使用fill_parent,請使用match_parent。 (前者已棄用)。並檢查alecnash答案,你不必在那裏使用「+」,+是創建一個新的id,而不是引用現有的。 –