我正在制作布局并使用 layout_weight 和 weight_sum。我正在将线性布局的方向设置为水平,这样我就可以将 imageview 的宽度设置为屏幕的 1/3。但是我不知道如何将imageview的高度设置为屏幕的1/3。
请帮我从布局 xml 中将 imageview 高度设置为屏幕的 1/3。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:id="@+id/savedImageView"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:background="@drawable/background" />
</LinearLayout>
提前致谢
最佳答案
使用这个:
int displayWidth = getWindowManager().getDefaultDisplay().getHeight();
ImageView imageView = (ImageView)findViewById(R.id.image);
imageView.getLayoutParams().height = displayWidth / 3;
关于android - 根据布局中的屏幕设置imageview的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17944910/