Попробуйте приведенный ниже код, возможно, вам подойдет, где я создал собственный относительный макет
package com.test;
public class MySquareRelativeLayout extends RelativeLayout {
public MySquareRelativeLayout(Context context) {
super(context);
}
public MySquareRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MySquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(VERSION_CODES.LOLLIPOP)
public MySquareRelativeLayout(Context context, AttributeSet attrs,int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Set a square layout.
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
}
<?xml version="1.0" encoding="utf-8"?>
<com.test.MySquareRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/elementRootView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:textAlignment="center"
tools:text="Long title long title long title(560)" />
</com.test.MySquareRelativeLayout>