我正在使用 PercentFrameLayout
作为 RecyclerView
中的一个项目,下面是我的布局。 PercentFrameLayout
没有出现。它没有显示。
我在这里遗漏了什么......?
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentFrameLayout 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="wrap_content">
<ImageView
android:id="@+id/header_image_view"
android:layout_width="match_parent"
app:layout_heightPercent="12%"
android:background="@drawable/placeholder_image"/>
</android.support.percent.PercentFrameLayout>
最佳答案
当您使用 layout_heightPercent
时,您要求分配给 PercentFrameLayout
的空间的百分比 - 即,如果 PercentFrameLayout
100dp
的高度,具有 layout_heightPercent="12%"
的 subview 将被赋予 12dp
。由于您的 PercentFrameLayout
没有其他子项并且是 wrap_content
,因此没有明确指示未指定值的 12% 是多少,导致根本没有分配空间。
如果您尝试将 View 的大小设置为总屏幕大小的百分比或 RecyclerView
可用的总可见高度的百分比,则必须在其他地方执行此操作,理想情况下作为 LinearLayoutManager
的子类,因为它控制着单个元素的高度。
关于android - PercentFrameLayout 作为 Recycler View 中的一个项目不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33603700/