Как сделать квадрат для просмотра галереи?

я использую этот метод LINK для создания recyclerview с помощью GridLayoutManager для столбцы autospan, но мне не удалось создать квадратный фиктивный макет для просмотра держателя. Я намерен имитировать галерею с помощью 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>


person Rulogarcillan    schedule 22.12.2014    source источник


Ответы (1)


Проверьте этот ответ, но в основном вы можете создать собственный SquareRelativeLayout, а затем переопределить метод onMeasure, чтобы он всегда был квадратным, как это :

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