I try to display an ImageView as a square inside a RecyclerView's element whatever is the element's height.
Here is what I would like to have:

Here is my xml :
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.percent.PercentFrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
>
<ImageView
android:scaleType="centerCrop"
app:layout_heightPercent="100%"
app:layout_aspectRatio="100%"/>
</android.support.percent.PercentFrameLayout>
<!-- other views -->
</RelativeLayout>
And here is what i have got (the ImageView disapeared):

(Excuse me if my english is bad)


You need to move your Percent layout one step higher in the hierarchy:
This approach assumes that your other views has a set height - if they have a variable height, then your image is going to also have a variable height (since it is using
layout_heightPercent="100%".If instead you want your images to be a specific size consistently, you'd instead want a layout such as
In this case, the width would be a fixed percentage of your total width (you could also use
layout_width="@dimen/fixed_width") and the height would be equal to that width.