I'm using the PercentFrameLayout
as an item in RecyclerView
below is my layout. PercentFrameLayout
is not appearing. It's not showing up.
Anything I'm missing here..?
<?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>
When you use
layout_heightPercent
, you are asking for a percentage of the space allotted to thePercentFrameLayout
- i.e., if thePercentFrameLayout
had a height of100dp
, a child view with alayout_heightPercent="12%"
would be given12dp
. As yourPercentFrameLayout
has no other children and iswrap_content
, there's no clear indication what 12% of an unspecified value is, leading to no space being allocated at all.If you're trying to set the size of the view as a percentage of the total screen size or of the total visible height available to the
RecyclerView
, you'll have to do that elsewhere, ideally as a subclass ofLinearLayoutManager
as that is what is controlling the height of individual elements.