How to make a square to view a gallery?

159 Views Asked by At

im using this metod LINK for generated a recyclerview with GridLayoutManager to autospan columns but i fail to make a square dummy layout for holderview, My intention is to imitate a gallery using recyclerview,

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/white"
android:orientation="vertical"
android:padding="1dp">


<ImageView
    android:id="@+id/txt"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"/>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="20dp"
    android:layout_gravity="center_horizontal|bottom"  
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true">

    <TextView
        android:id="@+id/card_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="folder"
        android:textSize="12dp"
        android:textStyle="bold"/>

</FrameLayout>

1

There are 1 best solutions below

0
On

Check out this answer, but basically you can create a custom SquareRelativeLayout and then override the onMeasure method so that it's always square like this:

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // Set a square layout.
    super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}