2016-08-23 41 views
3

我的启动画面是layer-list作为应用程序主题中的背景可绘制。下面是它:如何在启动屏幕后进行布局

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> 

正如你看到的,我把标志从上边距100dp。然后我尝试做同样的在我的片段布局:

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> 

但在布局中的标志似乎比在启动屏幕上的标志下。我想,问题在于Activity的默认边距。但如果我设置:

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

什么也没有发生。我总是看到标识从顶部“跳跃”下降10-20 dp。我怎样才能避免它?

编辑:我的活动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> 

编辑2:我试图手动拿起距离,如果我设置<item android:top="125dp">(或126dp),并留下android:layout_marginTop="100dp"我没有看到“跳”。这意味着差值是25或26 dp,但它们在哪里?

编辑3:根据Bryan的回答,问题只存在于Android 4.4(API 19)及以上版本。为了避免它,我在文件夹values-19推翻styles.xml有:

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

你可以发布屏幕 –

+0

的截图,你可能需要从你的activity_main.xml中删除margin和padding如果存在有 –

+0

按我的想法在闪屏你隐藏了'ToolBar'并且在Fragment中设置为'VISIBLE',这就是为什么它在两个屏幕中都看起来像上面和下面。 – Ironman

回答

1

看来你使用的闪屏不考虑status bar的尺寸绘制的,但Activity一样。这是你观察到的〜25dp的差异,尽管〜25dp的这个高度不能保证在所有设备上都是相同的。

+0

正是!谢谢!它仅在Android 4.4及更高版本中跳转。 –

0

也许问题是在ActionBarSize,尝试将其添加到闪屏:

没有程序兼容性

android:paddingTop="?android:attr/actionBarSize" 

随着程序兼容性

android:paddingTop="?attr/actionBarSize" 

或者,如果你愿意, (尽管可能被认为是不好的做法),您可以设置一个负填充值i N使用数据的活动布局结合:

android:paddingTop="@{-1 * ?android:actionBarSize}" 
+0

启动画面是一个'图层列表'。它没有'android:paddingTop'。反正这个问题已经解决了 –