Answers for "css resize image to fit in grid"

CSS
3

fit image in grid css

.photo > img {
  object-fit: cover;
  width: 100%;
  max-height: 100%;
}
Posted by: Guest on April-12-2021
0

image view auto size gridlayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
    android:id="@+id/first"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="3" >

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"

        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />
    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />
</LinearLayout>
<LinearLayout
    android:id="@+id/second"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/first"
    android:weightSum="3" >

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />
    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />
    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />
</LinearLayout>
<LinearLayout
    android:id="@+id/third"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/second"
    android:weightSum="3" >

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />
    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />
</LinearLayout>
<LinearLayout
    android:id="@+id/fourth"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/third"
    android:weightSum="3" >

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@drawable/ic_launcher"
        android:scaleType="centerInside"
        android:text="1" />
</LinearLayout>
Posted by: Guest on December-25-2021

Browse Popular Code Answers by Language