T
T
Tsuzukeru2021-10-14 13:23:14
Android
Tsuzukeru, 2021-10-14 13:23:14

How to constrain an ImageView with maxWidith and maxHeight?

I have a ShapableImageView and I need to constrain it with the maxHeight and maxWidth attributes. android:adjustViewBounds="true" - doesn't help. If you put a large image - ShappableImageView stretches above the limits indicated in maxWidith and maxHeight.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxWidth="@dimen/grid_12"
        android:maxHeight="@dimen/grid_12"
        android:background="@drawable/img"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:shapeAppearanceOverlay="@style/Circular.Corner_20" />

</androidx.constraintlayout.widget.ConstraintLayout>


If I add android:adjustViewBounds - ShapableImageView becomes rectangular like the original picture, and I need a square ShapableImageView
4ebd7806-9f4b-4e8c-9d40-f43aa40bef5b? Jwt-sign = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiYWUyNzM3MDktMWJmYS00YTZmLTgyNDgtODFkNWUzNWU2YTZkIiwiZXhwIjoxNjM0MjExMjM0fQ.BXAE9daM8OFi2zMKy_DmiPrIFwgwLoY2GFTGBg3gtm4

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question