【发布时间】:2019-03-30 05:41:38
【问题描述】:
我可以在XML中设置Android ImageView的宽度值而不改变它原来的初始比例吗?
我在 java 中解决了这个问题,但我不能在 Android XML 中做同样的事情。
到目前为止我尝试了什么:
int width = (inital width);
int height = (inital height);
int fixedWidth = Resources.getSystem().getDisplayMetrics().widthPixels >> 1;
int fixedHeight = (fixedWidth * height ) / (width); // 50% width of screen
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(fixedWidth, fixedHeight);
imageView.setLayoutParams(layoutParams);
【问题讨论】: