我有一个 ListView,其中填充了 RelativeLayouts。这些 RelativeLayouts 的内容可以改变,从而分别改变它们的高度。在每个 RelativeLayout 上,我在布局的左侧有一个与布局高度匹配的小垂直条。
它的外观与此类似 -> Link
虽然出于某种原因,我使用的 View 对象没有扩展到布局的高度。
我做错了什么?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/post"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/column_post_selector"
android:orientation="horizontal" >
<!-- Status bar (THIS ISN'T FILLING TO PARENTS' HEIGHT) -->
<View
android:id="@+id/status"
android:layout_width="3dp"
android:layout_height="fill_parent"
android:layout_alignLeft="@id/post"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:background="#33B5E5" />
<ImageView
android:id="@+id/thumbnail"
android:layout_width="80dip"
android:layout_height="80dip"
android:layout_toRightOf="@id/status"
android:contentDescription="@string/empty"
android:layout_marginRight="5dp"
android:scaleType="fitStart" />
<!-- Title -->
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/post"
android:layout_toRightOf="@id/thumbnail"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="sans" />
<!-- Rightend Duration -->
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/title"
android:layout_marginRight="5dip"
android:gravity="right"
android:textColor="#10bcc9"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
最佳答案
我的 RecyclerView
的单元格中有一个类似的问题,它有一个 RelativeLayout 作为根元素。
我的解决方法是在根 RelativeLayout 元素周围包装一个额外的 LinearLayout。
所以你的卡片看起来像这样:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/view_with_same_height_as_parent"
android:layout_width="10dp"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"/>
...
</RelativeLayout>
</LinearLayout>
关于android - RelativeLayout 的子级未填充 RelativeLayout 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15993030/