Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question