Center image in the middle of Android screen

Asked

Viewed 3,394 times

2

How do I align an image in the center of the screen on Android? I’m using the code below, but it’s centered at the top of the screen:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="br.com.projeto.acessosistema.SplashActitivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="60dp"
        android:contentDescription="@string/logomarca"
        app:srcCompat="@drawable/logo" />
</LinearLayout>
  • I got it, I switched android:layout_gravity="center_horizontal" by android:layout_gravity="center"

  • 1

    That’s right! Please mark the answer as correct!

  • Sorry Tulio for the delay. I marked as correct answer. Thank you.

1 answer

3


Change the value of the attribute android:layout_gravity for:

android:layout_gravity="center_horizontal|center_vertical"

or just:

android:layout_gravity="center"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.