我的启动画面是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>
你可以发布屏幕 –
的截图,你可能需要从你的activity_main.xml中删除margin和padding如果存在有 –
按我的想法在闪屏你隐藏了'ToolBar'并且在Fragment中设置为'VISIBLE',这就是为什么它在两个屏幕中都看起来像上面和下面。 – Ironman