如何在android中以与屏幕宽度相等的方式显示相同大小的图像

如何在android中以与屏幕宽度相等的方式显示相同大小的图像,android,android-layout,Android,Android Layout,我想显示与屏幕宽度相等的图像。以下是我的代码:- <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="wrap_content"

我想显示与屏幕宽度相等的图像。以下是我的代码:-

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/m"
            android:padding="10dp"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/m"
            android:padding="10dp"/>

    </LinearLayout>

我的布局如下所示:-


任何人都可以帮助我解决这个问题。

使用
布局高度
属性:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:weightSum="1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:src="@drawable/m"
        android:padding="10dp"
        android:layout_weight="0.5"/>

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:src="@drawable/m"
        android:padding="10dp"
        android:layout_weight="0.5"/>

</LinearLayout>

如果我以编程方式创建了Imageview,那么我该怎么做呢?为什么要使用
布局\u weight=“0.5”
??我的意思是,为什么不在每一个页面中使用
layout\u weight=“1”
?顺便说一句,
android:weightSum=“1”
不是必需的。属性
“fill\u parent”
已被弃用,请改用
“match\u parent”
。@astinx 0.5或1或任何您想要的值,重要的是对两幅图像使用相同的值。你是正确的家长,我还没有注意到这一点,我会更新我的答案。
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
params.weight = 0.5f;
ImageView = new ImageView(this);
myImageView.setLayoutParams(params);