Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make image appear half of the screen [duplicate]

I am having trouble to make my imageview appear half of the screen can someone help. here is my xml file. It should take up half of the screen size and also the linear layout with the textview should be at the footer of the imageview.

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@drawable/fond" >

<RelativeLayout

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:layout_alignParentLeft="true"

    android:layout_below="@+id/relativeLayout1" >

    <RelativeLayout

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:layout_alignParentLeft="true" >

        <WebView

            android:id="@+id/webcontent"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_alignParentLeft="true"

            android:layout_alignParentTop="true"

            android:layout_marginTop="151dp" />

    </RelativeLayout>

    <ImageView

        android:id="@+id/image_actualitedetails"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:layout_alignParentTop="true"

        android:layout_centerHorizontal="true"

        android:src="@drawable/six_yamaha" />

    <LinearLayout

        android:id="@+id/linearvideo"

        android:layout_width="fill_parent"

        android:layout_height="65dp"

        android:layout_alignBottom="@+id/image_actualitedetails"

        android:layout_alignParentLeft="true"

        android:background="#88FFFFFF"

        android:gravity="center"

        android:paddingLeft="@dimen/fourdp"

        android:paddingRight="@dimen/fourdp" >


        <TextView

            android:id="@+id/text_actualites"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="TextView"

            android:textColor="@color/tabDark"

            android:textStyle="bold" />

    </LinearLayout>


</RelativeLayout>

<RelativeLayout

    android:id="@+id/relativeLayout1"

    android:layout_width="fill_parent"

    android:layout_height="75dp"

    android:layout_alignParentLeft="true"

    android:layout_alignParentTop="true"

    android:background="@drawable/header" >

    <Button

        android:id="@+id/boutton_retour"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentLeft="true"

        android:layout_centerVertical="true"

        android:layout_marginLeft="14dp"

        android:background="@drawable/back" />

</RelativeLayout>

like image 677
Dimitri Avatar asked Jan 27 '13 04:01

Dimitri


2 Answers

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="@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!

like image 80
zTrix Avatar answered Oct 14 '22 13:10

zTrix


Just if someone wants landscape version its almost the same :)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:baselineAligned="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:background="#ff0000" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/adele" />
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:background="#00ff00" />
</LinearLayout>
like image 31
Javier Avatar answered Oct 14 '22 11:10

Javier