How to align two images one in center and one in bottom using LinearLayout
because as i found RelativeLayout marked as legacy
Here question but for splash screen
Android: how to align 2 images on a splash screen
Asked
Active
Viewed 491 times
0

ButuzGOL
- 1,233
- 2
- 13
- 27
-
any update for this question ? – John Joe Apr 22 '18 at 16:29
3 Answers
1
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:layout_weight="1"
android:src="@drawable/image_1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="100dp"
android:src="@drawable/image_2"/>
</LinearLayout>

gusgol
- 483
- 5
- 11
0
How to align two images one in center and one in bottom using LinearLayout
For LinearLayout
, you can set the orientation to vertical
To make the image center, use android:layout_gravity="center_horizontal"
Code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<ImageView
android:layout_marginTop="90dp"
android:layout_gravity="center_horizontal"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@drawable/image"/>
<ImageView
android:layout_marginTop="30dp"
android:layout_gravity="center_horizontal"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/image2"/>
</LinearLayout>
Output

John Joe
- 12,412
- 16
- 70
- 135
0
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView2"
android:layout_width="89dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="100dp"
android:layout_marginTop="190dp"
android:layout_weight="1"
app:srcCompat="@drawable/child_big" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="100dp"
app:srcCompat="@android:drawable/btn_star" />
</LinearLayout>
Play with marginBottom and marginTop attributes!