Center image in the middle of the Android screen

0

How do I align an image in the center of the screen on Android? I'm using the code below but it gets 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>
    
asked by anonymous 29.01.2018 / 12:59

1 answer

2

Change the android: layout_gravity attribute value to:

android:layout_gravity="center_horizontal|center_vertical"

or just:

android:layout_gravity="center"
    
29.01.2018 / 14:13