是否可以創建一個啓動畫面,其中的徽標可以保持其縱橫比,而背景圖像可以獨立調整大小?我目前正在使用幾個不同分辨率的.png文件,並且在大多數設備上看起來都很棒。不過,有幾款手機嚴重扭曲了我的標誌(即三星S8,移動垂直屏幕空間)。沒有標誌失真的Android啓動畫面
我可以處理我的閃屏背景的一些失真,但瘦/壓扁的標誌是不可接受的。有誰知道如何做到這一點?矢量可繪製的標誌會比新的佈局的.png更好嗎?
是否可以創建一個啓動畫面,其中的徽標可以保持其縱橫比,而背景圖像可以獨立調整大小?我目前正在使用幾個不同分辨率的.png文件,並且在大多數設備上看起來都很棒。不過,有幾款手機嚴重扭曲了我的標誌(即三星S8,移動垂直屏幕空間)。沒有標誌失真的Android啓動畫面
我可以處理我的閃屏背景的一些失真,但瘦/壓扁的標誌是不可接受的。有誰知道如何做到這一點?矢量可繪製的標誌會比新的佈局的.png更好嗎?
如果您只有一個肖像圖像爲您的啓動畫面,這是一個解決方案,這是一個全屏的肖像,並居中,但不是在edit:
肖像
景觀:
splash_screen.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutSplash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/splash_screen_background">
<ImageView
android:contentDescription="@string/splash_screen_description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
style="@style/SplashScreen" />
</LinearLayout>
值/ styles.xml
<style name="SplashScreen">
<item name="android:src">@drawable/splash</item>
<item name="android:adjustViewBounds">true</item>
<item name="android:scaleType">fitCenter</item>
</style>
值端口/ styles.xml
<style name="SplashScreen">
<item name="android:src">@drawable/splash</item>
<item name="android:adjustViewBounds">true</item>
<item name="android:scaleType">centerCrop</item>
</style>
你看過維護ImageView
的長寬比嗎?這是一個相關的問題是應該指向你在正確的方向:How to scale an Image in ImageView to keep the aspect ratio
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/logo"/>
</RelativeLayout>
這將做到這一點
無需根本不使用佈局,使用LayeredList並設置i t作爲背景。這是一個例子;
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/gray"/>
<item>
<bitmap android:gravity="center" android:src="@drawable/splash_image"/>
</item>
</layer-list>
在layout.xml中呈現splash視圖而不是作爲主題背景(與其他建議一樣)將花費更長的時間來加載。這是因爲應用程序的主題首先被加載,然後Activity被構造並且佈局最後膨脹。由於啓動畫面的目的是在應用程序加載時顯示某些內容,因此加載閃屏時延遲約0.5秒會導致明顯的延遲。將splash添加爲主題windowBackground效果更好(點擊啓動器圖標後幾乎立即渲染),但有一些限制需要解決。根據屏幕寬度定義多個徽標大小的當前方法是處理這種情況的正確方法。下面是一個例子的結構,它處理前,後的Android V21之間的差異:
值/的themes.xml:
<style name="SplashThemeCommon" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@drawable/splash_logo_theme</item>
</style>
<style name="SplashTheme" parent="SplashThemeCommon">
<item name="android:windowFullscreen">true</item>
</style>
值-V21 /的themes.xml:
<style name="SplashTheme" parent="SplashThemeCommon">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
抽拉/ splash_logo_theme.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:gravity="center"
android:src="@drawable/splash_logo"/>
</item>
</layer-list>
接下來,您可以包含「splash_logo」的副本。。PNG」爲不同的屏幕配置你有幾個合理的選擇這裏一個詳盡的方法可能包括針對每個屏幕尺寸不同的標識:
「swXXXdp」表示XXX是dp中的最小屏幕尺寸(寬度或高度)。 820dp將是一個巨大的平板電腦,320dp將是一箇舊的小型設備,今天大多數旗艦設備將在400dp類別。 450dp寬的設備將使用400dp圖像。
爲什麼我在這裏定義xxxhdpi?因爲如果你沒有指定,Android會認爲它是一個mdpi圖像,並嘗試升級/調整高分辨率設備的大小(目前大多數旗艦手機都是xxhdpi)。這種放大將導致您的圖像塊狀,並比原來的大。通過在這裏指定xxxhdpi,Android只會嘗試縮小圖像尺寸,以確保圖像不會變得塊狀;這是一個優化,所以我們不需要爲ldpi,mdpi,hdpi,xhdpi等定義單獨的圖像。
雖然APK中有6個圖像,但這種方式很浪費。我們可以進一步優化此方法,以便在應用中包含更少的圖像並確保更小的APK大小。相反,讓我們僅包括以下兩個圖像:
爲600dp和更大(片劑)具有任何裝置一個較大的圖像副本以利用較大的屏幕空間,而所有其他手機使用較小的副本,並且沒有屏幕寬度限定符。這裏的缺點是,由於每個垃圾箱都覆蓋瞭如此大範圍的屏幕寬度,因此4英寸設備上的徽標將佔用屏幕的大部分,而不是6英寸設備。這是減小APK大小的妥協方案,只要圖像在最小的設備上永遠不會被切斷,大多數用戶都不會注意到。
那麼我們應該包括多大的png?它們需要在主題中顯示特定大小,因爲與layout.xml不同,我們無法在XML中指定寬度/高度(可繪製的寬度/高度支持僅在API 23中添加)。這意味着如果你包含一個非最優的PNG大小,它會顯得太小或兩個大;如果它太大,它實際上會被切斷。一個好的計劃,以獲得正確尺寸是:
您如何知道哪個設備屏幕分辨率屬於哪個swXXXdp類別?這需要一個簡單的計算。讓我們看一下像素XL:
是你的形象(imageview)有重量和身高的wrap_content? – DroiDev
不,它是match_parent。 – deMouser
如果我明白,你有一個背景圖像,然後在它上面的圖像。和圖像(你的圖標)在某些設備上變形? – DroiDev