I'm trying to put as an image of the background an image that I want it to be exactly centered vertically and horizontally (the image is a ball). So the goal is to stay horizontally match_parent
and vertically wrap_content
to stay right in the center of the screen.
I'm not getting this effect because I'm also using the Toolbar and when I get the image well Toolbar also comes to the center. Can someone help me please?
Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_gravity="center"
android:orientation="vertical"
android:background="@drawable/ball"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_gravity="center"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="@color/grey0">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/white"
android:textSize="26sp"
android:textStyle="bold"
android:gravity="center"
android:id="@+id/toolbar_title"/>
</android.support.v7.widget.Toolbar>
<LinearLayout
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> (...) </LinearLayout> </LinearLayout>