上的應用我工作,我們有一個閃屏由RelativeLayout的和標誌的中心(和一些其他的東西,就像一個正在加載的旋轉等):層列表windowBackground的佈局邊界是否與膨脹佈局不同?
fragment_splash_image.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="@drawable/loading_screen_bg"
... >
<ImageView
android:id="@+id/universal_loading_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/logo_large"
... />
... other stuff ...
</RelativeLayout>
要確保有不只是我們的啓動畫面前的短暫黑屏,我們有一個活動在styles.xml一個SplashTheme。它的android:windowBackground
只是一個層次列表,並且標誌再次位於中心,希望徽標看起來會保持在屏幕中間,而fragment_splash_image中的其他內容也會出現。
splash_placeholder.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item android:drawable="@drawable/loading_screen_gradient"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/logo_large"/>
</item>
</layer-list>
注意@drawable/logo_large
是在各自相同的標誌,並居中在每個屏幕上。預期的行爲是它根本不應該移動。
反正fragment_splash_image
膨脹中,從FrameLayout裏延伸的類,在此方法:
private void inflateContent() {
final View splashImageFragment = LayoutInflater.from(getContext()).inflate(R.layout.fragment_splash_image, this, true);
final ImageView brandLogo = (ImageView) splashImageFragment.findViewById(R.id.universal_loading_logo);
final int statusBarHeight = ScreenUtils.getStatusBarHeight(getResources());
final int navBarHeight = !ScreenUtils.hasSoftNavBar() ? 0 : ScreenUtils.getNavigationBarHeight(getResources());
brandLogo.setPadding(0, 0, 0, statusBarHeight - navBarHeight);
}
現在,這是怎麼回事在那裏是最初,我們只是誇大片段原樣。不幸的是,這會導致飛濺片段中的徽標與飛濺的佔位符徽標相比在一小段距離上跳起,這取決於所測試的設備。在我的Galaxy S6手機上,我發現佔位符閃屏可能包含狀態欄高度,所以我將它作爲填充添加到徽標底部。該設備已解決問題。然而,在Nexus 7有一個軟導航欄,標誌仍然跳得很遠。我得出的結論是,也許它也包含了佈局邊界中的導航欄高度,並寫下了上面的內容:bottom padding = statusBarHeight - navBarHeight,其中navBarHeight對於具有硬導航按鈕的設備爲0。
這適用於這兩種設備......然後我在Google Pixel上測試。徽標跳下來。這隻適用於像素,如果我將底部填充設置爲0,並且頂部填充到狀態欄高度。
我很難過。這裏確定兩種佈局的高度是什麼?他們明顯不同,我不確定如何確保徽標不會從任何設備上的某個屏幕跳到下一個屏幕。提前致謝!