0

I want to attach ImageViews to each other. I tried to set gravity and alignParentRight/alignParentLeft but can`t achieve my goal. For simplicity I have set color backgrounds for ViewGroups. Do you have any ideas how to make it done?

enter image description here

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/share_dope_max_image_height"
        android:layout_marginTop="@dimen/share_dope_margin_3"
        android:background="#0DD"
        android:orientation="horizontal"
        android:paddingLeft="@dimen/share_dope_images_container_horizontal_padding"
        android:paddingRight="@dimen/share_dope_images_container_horizontal_padding">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:background="#D0D"
            android:gravity="right"
            >
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_alignParentRight="true"
                    android:src="@drawable/girl3" />

        </RelativeLayout>

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

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_alignParentLeft="true"
                    android:src="@drawable/girl4" />

        </RelativeLayout>

    </LinearLayout>
Oleh Liskovych
  • 991
  • 3
  • 13
  • 31

2 Answers2

1

Try this:

  • Use LinearLayout as a parent
  • Set the Layout orientation to horizontal
  • put the imageView side by side
  • set the weight for each imageView to same number e.g. 1

You should have both images side by side

Want2bExpert
  • 527
  • 4
  • 11
1

Found the exact solution for this problem here: http://www.ryadel.com/en/android-proportionally-stretch-imageview-fit-whole-screen-width-maintaining-aspect-ratio/

Oleh Liskovych
  • 991
  • 3
  • 13
  • 31