T
T
TimkaTV2015-07-08 10:17:56
Android
TimkaTV, 2015-07-08 10:17:56

How to correct the scale of the image?

Good afternoon,
There is a Drawer Layout with a List, each element of which has a markup

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:backgroundTint="#000000">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:src="@drawable/lectures"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

The picture is square, but in the process it stretches (shrinks along the vertical axis)
How to deal with this? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Gamega, 2015-07-08
@gadfi

you have wrap_content image dimensions and android:scaleType
developer.alexanderklimov.ru/android/views/imagevi...
update:
I'm sure they did something wrong, but sometimes when you need a square image of an unknown size (for example, in a list) I use such a class

public class SquaredImageView extends ImageView {
    public SquaredImageView(Context context) {
        super(context);
    }

    public SquaredImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question