EugeneS
EugeneS

Reputation: 1140

How to put a picture on top of a background image in the center?

There is a picture that needs to be placed in the center of the background image. Why doesn't the picture become centered on top of another background image? It turns out at the top left, but not in the center.

Here is the code:

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:gravity="center">
 <ImageView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:scaleType="fitXY"
android:src="@drawable/background"/>

 <ImageView
    android:id="@+id/splash_logo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:scaleType="centerCrop"
    android:src="@drawable/splashlogo2" />
 </RelativeLayout>

Upvotes: 0

Views: 70

Answers (1)

Maksym V.
Maksym V.

Reputation: 2937

Have you tried replacing android:gravity... with android:layout_centerInParent="true"

Upvotes: 2

Related Questions