我认为问题是,Recycler没有高度。所以我的百分比布局不能用100%填充'0'的高度 如何获得RecyclerView的每个孩子的身高?
Recycler的内容(percentLayout):
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#000000">
<TextView
app:layout_widthPercent="5%"
app:layout_heightPercent="100%"
app:layout_marginTopPercent="5%"
app:layout_marginLeftPercent="2%"
app:layout_marginRightPercent="75%"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/txt_roomname_map"
android:background="#3c64f6"
android:textColor="#ffffff"
/>
<TextView
app:layout_widthPercent="35%"
app:layout_heightPercent="100%"
app:layout_marginTopPercent="5%"
app:layout_marginLeftPercent="13%"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/txt_weapons_in_room_map"
android:background="#3c64f6"
android:textColor="#ffffff"
/>
<TextView
app:layout_widthPercent="35%"
app:layout_heightPercent="100%"
app:layout_marginTopPercent="5%"
app:layout_marginLeftPercent="52%"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/txt_weapons_in_room_map2"
android:background="#3c64f6"
android:textColor="#ffffff"/>
<TextView
app:layout_widthPercent="5%"
app:layout_heightPercent="100%"
app:layout_marginTopPercent="5%"
app:layout_marginLeftPercent="93%"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/txt_roomname_map2"
android:background="#3c64f6"
android:textColor="#ffffff" />
</android.support.percent.PercentRelativeLayout>
RecyclerLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#000000">
<android.support.v7.widget.RecyclerView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/recyclerview"
android:layout_below="@+id/imageView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="@+id/imageView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
非常感谢!
答案 0 :(得分:0)
您无法将PercentRelativeLayout的高度设置为屏幕的百分比,因为您无法从布局项访问RecyclerView的高度。
但您可以将宽度设置为100%并使用layout_aspectRatio。