简体   繁体   中英

how to show same size images in equal to width of screen in android

I want to show images in equal to width of screen.here my code:-

<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>

My layout look like:-

Anyone can help me how i solved this problem.

Use layout_height attribute:

<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>

UPDATE:

If you want to do that from java code:

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
params.weight = 0.5f;
ImageView = new ImageView(this);
myImageView.setLayoutParams(params);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM