简体   繁体   中英

Android 2 Image view with half display in left side and half display in right side

I am drawing a Linear layout in Android to display 2 images with half image in left side and half image.

I draw like this :

在此处输入图片说明

but I want to draw like below, can you please help me to draw the image like below.

在此处输入图片说明

My layout file is here:

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

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="10dp"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1.5" >

        <ImageView
            android:id="@+id/sideLeft"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.5"
            android:layout_marginBottom="10dp"
            android:background="@drawable/user"
            android:scaleType="centerCrop" />

        <ImageView
            android:id="@+id/sideRight"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="1dp"
            android:layout_weight="1.5"
            android:layout_marginBottom="10dp"
            android:background="@drawable/user"
            android:scaleType="centerCrop" />
    </LinearLayout>
</LinearLayout>

</RelativeLayout>

That will look like a 1 image.

Thanks In Advance!

You need to work on java for such output,

Set both image fit center, And from Java set first imageview's right padding as -width/2, and second imageview's left padding as -width/2. Here width is imageview's width.

It may help you.

Try this

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:gravity="center" 
    android:layout_weight="1.5" >

    <ImageView
        android:id="@+id/sideLeft"
       android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:background="@drawable/user"
        android:scaleType="centerCrop" />

    <ImageView
        android:id="@+id/sideRight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="1dp"

        android:layout_marginBottom="10dp"
        android:background="@drawable/user"
        android:scaleType="centerCrop" />
</LinearLayout>

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