Alexander Tumanin - 11 months ago 46
Android Question

# How to make an identic layout after splash screen

My splash screen is a

layer-list
drawable as background in app theme. Here is it:

background_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:drawable="@color/dark_blue"/>

<item android:top="100dp">
<bitmap
android:gravity="top"
android:src="@mipmap/img_logo"/>
</item>

</layer-list>


As you see, I place the logo with margin
100dp
from the top. Then I try to do the same in my fragment layout:

fragment_start.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/bg_create_account">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/img_logo"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp" />

</RelativeLayout>


But the logo in the layout appears lower than logo on the splash screen. I thought, the problem is in the default margin of
Activity
. But if I set:

<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>


Nothing still happens. I always see the "jump" of logo from top to down about 10-20 dp. How can I avoid it?

EDIT: My activity xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>

</LinearLayout>


EDIT 2: I tried to pick up the distance manually and if I set
<item android:top="125dp">
(or 126dp) and leave
android:layout_marginTop="100dp"
I see no "jump". It means the difference is 25 or 26 dp, but where are they?

EDIT 3: according to answer from Bryan the issue exists only in Android 4.4(API 19) and above. To avoid it I overrode
styles.xml
in folder
values-19
with:

<item name="android:windowTranslucentStatus">true</item>


It seems drawable that you use for the splash screen does not take into account the size of the status bar, but the Activity does. This is the ~25dp difference you are observing, though this height of ~25dp is not guaranteed to be the same on all devices.