M
M
mitaichik2016-03-27 19:29:34
Android
mitaichik, 2016-03-27 19:29:34

How to set the height of a component in xml depending on the width?

Hello!
I need to set the height of a component to be five times smaller than the width. Is it possible to do this in xml markup?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Gamega, 2016-03-27
@mitaichik

Make your own component, an example for a square ImageVIew, by analogy, set any ratio

ublic class SquareImageView  extends ImageView {

  ...

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

    int width = getMeasuredWidth();
    setMeasuredDimension(width, width);
  }

  ...

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question