PercentFrameLayout as an item in Recycler view not working

1.2k Views Asked by At

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>
1

There are 1 best solutions below

4
On

When you use layout_heightPercent, you are asking for a percentage of the space allotted to the PercentFrameLayout - i.e., if the PercentFrameLayout had a height of 100dp, a child view with a layout_heightPercent="12%" would be given 12dp. As your PercentFrameLayout has no other children and is wrap_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 of LinearLayoutManager as that is what is controlling the height of individual elements.