ImageView 宽度 = 0.75x 屏幕宽度 & 高度 = 1.5 x 新 ImageView 宽度 XML

ImageView width = 0.75x screen width & height = 1.5 x new ImageView width XML

我正在使用 Glide 将图像加载到 ImageView 中。

在从 Internet 加载图像之前,我添加了一个 占位符图像,直到图像完成加载。

幸运的是,我正在加载的图像具有固定的纵横比,即 height/width = 1.5

我有以下要求: 图像视图的宽度应占屏幕宽度的 75%。 高度应该正好是新屏幕宽度的 1.5 倍, 即

width = 0.75 * screenWidth; 
height = 1.5 * width;

目前我正在以这种方式以编程方式实现这个

mImageViewPic = (ImageView) view.findViewById(R.id.networkImageView);
mImageViewPic.requestLayout();

// 75% width of the screen taken by the image
mImageViewPic.getLayoutParams().width = (int) (getContext().getResources()
                                                .getDisplayMetrics().widthPixels * 0.75);

// height = 1.5 * width
mImageViewPic.getLayoutParams().height = (int) (mImageViewPic
                                                .getLayoutParams().width * 1.5);

我正在寻找的是通过 XML 而非编程方式满足这些要求的有效解决方案。
我知道您可以使用布局权重将宽度设置为 75 % 但是那之后你怎么设置高度呢?

希望我的要求很明确。提前致谢。

你可以在 Glide 中使用 override(w,h) 方法来调整大小

您可以使用 PercentRelativeLayout。 例如,如果你想要 16:9 宽高比,你应该在你的 PercentRelativeLayout 中添加这样的东西:

 android:layout_width="300dp"
 app:layout_aspectRatio="178%"