Android 根据布局中的屏幕设置imageview的高度
我正在制作布局,并使用布局的重量和重量之和。我正在将线性布局的方向设置为水平,以便能够将imageview的宽度设置为屏幕的1/3。但是我不知道如何将imageview的高度设置为屏幕的1/3 请帮助我从布局xml中将imageview高度设置为屏幕的1/3Android 根据布局中的屏幕设置imageview的高度,android,android-layout,Android,Android Layout,我正在制作布局,并使用布局的重量和重量之和。我正在将线性布局的方向设置为水平,以便能够将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"
<?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>
提前谢谢你需要这样的东西吗?还是请详细说明你的问题,以便我能帮助你
<?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="414dp"
android:layout_weight="0.52"
android:background="@drawable/ic_launcher" />
</LinearLayout>
使用以下方法:
int displayWidth = getWindowManager().getDefaultDisplay().getHeight();
ImageView imageView = (ImageView)findViewById(R.id.image);
imageView.getLayoutParams().height = displayWidth / 3;
如果像这样放置外部水平线布局,则imageview的屏幕宽度和高度都将分别为1/3和1/3。内线布局是垂直的,所以如果您只需要1/3的屏幕高度,就可以使用它
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/out"
android:weightSum="3"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="3" >
<ImageView
android:id="@+id/savedImageView"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@drawable/yourdrawablename" />
</LinearLayout>
</LinearLayout>
根据该代码设置宽度,但不设置高度。我想通过weightsum和layout\u weight属性设置高度和宽度。上传图像如何显示布局我没有收到问题我的意思是我在问题中粘贴了上面的代码,其中它根据屏幕宽度设置imageview的宽度,但我想根据屏幕将高度和宽度设置为1/3。我成功地从布局属性设置了宽度和高度,但不能同时设置这两个属性。请检查我的答案,它同时处理宽度和高度。我想从xml布局中执行同样的操作。那么我该怎么做呢?似乎是可行的,除了一种情况,如果图像高度小于屏幕高度的1/3,它将不会被放大到屏幕高度的1/3,编辑:要使其工作,我们需要设置android:scaleType=“centerCrop”
在ImageView xml定义中。我使用它将ImageView设置为1/3,但内部线性布局覆盖屏幕的整个高度。我想它也应该是1/3。井的重量被用作水平或垂直,所以你不能像那样改变你的线性布局尺寸设置。您要求使用imageview,这是实现它的方法。如果您也希望获得外部布局的精确结果,则必须以编程方式进行。