Place the image partially above the toolbar
I would like how to render the image in my relative layout above (on the top layer) of my toolbar (in the same relative layout), not below. Any ideas? Location
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:src="@drawable/splash"
android:adjustViewBounds="true"
android:layout_below="@id/my_toolbar"
android:gravity="top"
android:layout_alignTop="@id/my_toolbar"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<include
android:id="@+id/my_toolbar"
layout="@layout/my_toolbar"
></include>
</RelativeLayout>
</FrameLayout>
toolbar
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:background="#7dca2c"
android:elevation="4dp"
>
</android.support.v7.widget.Toolbar>
+3
source to share
1 answer
You don't need it RelativeLayout
, yours FrameLayout
will handle it just fine.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/my_toolbar"
layout="@layout/my_toolbar"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:src="@drawable/splash"
android:adjustViewBounds="true"
android:layout_gravity="top|center_horizontally"/>
</FrameLayout>
With layout enabled as the first child, this will be the first level and the ImageView
second. Adding android:layout_gravity="top|center_horizontally"
in ImageView
then will correctly align it in ViewGroup
.
-1
source to share