如何将PercenRelativeLayout用于listView项 [英] How to use PercenRelativeLayout for listView item
问题描述
我正在尝试将 PercenRelativeLayout 用于 ListView ,但是它不起作用, 高度和宽度百分比将被忽略,并且列表视图中未显示任何内容. 它仅适用于棉花糖.
I'm trying to use PercenRelativeLayout into ListView, but it doesnot works, height and width percents are ignored and nothing were showing into the listview. it works only for marshmallows.
这是列表项xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:background="#d20404"
android:id="@+id/test_image_id"
android:layout_width="match_parent"
android:layout_height="300dp" />
<TextView
android:background="#000"
android:text="sfgfashdsfg"
android:layout_below="@+id/test_image_id"
app:layout_heightPercent="50%"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.percent.PercentRelativeLayout>
我在 github
推荐答案
我已向Google打开此问题. 答案是
I have opened this issue to google. The answer were
ListView行项目的高度指定不充分.
The height of your ListView row item is insufficiently specified.
第一个孩子说要占据行高的60%(请注意, 这是heightPercent而不是AspectRatio),第二个孩子说 它想占用行高的10%.但是什么都没有告诉ListView如何 整行想要的很高.因此最终它的高度为0.
The first child says it wants to take 60% of the row height (note that this is heightPercent and not aspectRatio), and the second child says it wants to take 10% of the row height. But nothing tells ListView how tall the entire row wants to be. So it ends up being with height 0.
请注意,height = match_parent的语义在ListView中不起作用 行,并且在任何特定的Android平台版本中都可以使用 (无论您能说出多少效果),这纯粹是偶然的.
Note that the semantics of height=match_parent do not work in ListView rows, and if this works in any one particular Android platform version (for however much you can say it works), it is purely incidental.
https://code.google.com/p/android /issues/detail?id = 202479
这篇关于如何将PercenRelativeLayout用于listView项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!