Make image appear half of the screen [duplicate]

Use LinearyLayout to wrap your ImageView and another invisible View, and set layout_weight both to 0.5, then the ImageView should be half the size.

Here is an example for you showing how to set the image half the screen size

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:background="#ff0000"
        >
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="https://stackoverflow.com/questions/14544327/@drawable/your_image"
            android:adjustViewBounds="true"
            />
    </RelativeLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:background="#00ff00"
        />
</LinearLayout>

And this is the result

enter image description here

If you want to put your image in center of the screen, you can use the same idea and set proper weight to achieve your goal. Good luck!

Leave a Comment