@korolevsky_s
iOS Developer

Как высоту imageView сделать равной его ширине?

Собственно imageView всегда должен быть квадратным на любом устройстве. Как сделать высоту равной ширине?
  • Вопрос задан
  • 227 просмотров
Решения вопроса 1
@korolevsky_s Автор вопроса
iOS Developer
Вот решение:
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

public class SquareImageView  extends ImageView {

    public SquareImageView(Context context) {
        super(context);
    }

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

    public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

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

        int width = getMeasuredWidth();
        setMeasuredDimension(width, width);
    }
}
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы