Reputation: 1243
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
Upvotes: 0
Views: 526
Reputation: 12803
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
Upvotes: 0
Reputation: 1
<?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!
Upvotes: 0
Reputation: 503
<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>
Upvotes: 1