Question layout. How can I display 1 image above, 1 image below

I have a vertical LinearLayout. I would like to place 1 ImageView at the top and 1 ImageView at the bottom of this LinearLayout. I tried putting "android: gravity =" top "and" android: gravity = "bottom" in each of the ImageViews, but both ImageViews are displayed at the top of the LinearLayout. Is there any way to fix this?

Thank.

   <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent">

   <ImageView
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon"
        android:gravity="top" />

   <ImageView
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon"
        android:gravity="bottom" />
   </LinearLayout>
+3
source share
2 answers

The easiest way to do this is RelativeLayout. Replace LinearLayoutwith LinearLayoutand change the first ImageViewto use android:layout_alignParentTop="true", and the second to android:layout_alignParentBottom="true".

+2
source

Erich WRT RelativeLayout. , LinearLayout, , "" , . (android:orientation="vertical"), ... :

<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon" />

    <ImageView
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon" />
</LinearLayout>

, , , - (untested):

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/button1"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:src="@drawable/icon" />

    <ImageView
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon" />
</LinearLayout>

, , , , .

0

Source: https://habr.com/ru/post/1732228/


All Articles