Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an identic layout after splash screen

Tags:

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>
like image 221
Alexander Tumanin Avatar asked Aug 23 '16 08:08

Alexander Tumanin


People also ask

How do you set a timer for splash screen?

you can use Sleep method like this in your Splash Activity onCreate method: Thread timer1 = new Thread(){ @Override public void run(){ try{ sleep(4000); } catch (InterruptedException e){ e. printStackTrace(); } finally{ Intent intent = new Intent(SplashActivity. this, NextActivity.

What is splash activity in Android?

Android Splash Screen is the first screen visible to the user when the application's launched. Splash screen is one of the most vital screens in the application since it's the user's first experience with the application.


1 Answers

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.

like image 143
Bryan Avatar answered Oct 04 '22 23:10

Bryan