我可以在不改变其原始初始比例的情况下在 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);
最佳答案
在您的 imageView 中添加属性
android:adjustViewBounds="true"
然后将你的高度包裹起来,这样你的高度就会有纵横比
关于android - 如何在保持宽高比的 XML 中更改 Android ImageView 的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55428550/