我的启动画面是一个
正如您所看到的,我将Logo与顶部保持
EDIT 2: 我尝试手动调整距离,如果我设置
EDIT 3: 根据Bryan的答案,此问题仅存在于Android 4.4(API 19)及以上版本。为了避免这种情况,我在文件夹
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>
正如您所看到的,我将Logo与顶部保持
100dp
的距离。然后我尝试在我的片段布局中做同样的事情:
< p > < em > 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>
但是在界面布局中的logo比启动屏幕上的logo位置低。我认为问题出现在Activity
的默认边距上。但如果我设置:
<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>
仍然没有任何反应。我总是看到标志从上往下“跳动”约10-20 dp。我该如何避免这种情况?
编辑:我的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: 我尝试手动调整距离,如果我设置
<item android:top="125dp">
(或126dp),并保留android:layout_marginTop="100dp"
,我就看不到“跳跃”了。这意味着差异为25或26 dp,但它们在哪里?EDIT 3: 根据Bryan的答案,此问题仅存在于Android 4.4(API 19)及以上版本。为了避免这种情况,我在文件夹
values-19
中覆盖了styles.xml
:<item name="android:windowTranslucentStatus">true</item>
ToolBar
,然后在片段中再次设置为VISIBLE
,这就是为什么它看起来像上下两个屏幕。 - Harshad PansuriyaToolBar
也不是原因。我在主题中和Activity/Fragment中都没有使用ToolBar
或ActionBar
。 - Alexander Tumanin