Android - 包含与 windowBackground 相同的可绘制对象在布局中大小不同
Android - Same drawable included as windowBackground not the same size when in layout
我正在创建一个带有图像的闪屏,并打算添加一个动画。所以我从这个开始 activity:
<activity
android:name=".activities.SplashActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这使用以下主题:
<style name="SplashTheme" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">@drawable/loading_page_4</item>
</style>
我正在使用它在布局呈现时立即显示图像。然后在 activity 的 onCreate 方法中,我设置了以下布局文件:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:foreground="@drawable/loading_page_4"
android:id="@+id/splash_color_layout" >
</FrameLayout>
出于某种原因,尽管是相同的可绘制对象,但在呈现页面时图像显示略有不同(它略微向下移动,甚至可能略微调整大小)。有没有一种方法可以使用相同的可绘制对象从主题背景无缝过渡到呈现的布局?
这里还有 activity class:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Splash screen view
setContentView(R.layout.activity_splash);
}
}
因此,这里的区别在于您的 Activity 的高度将不同于显示它的 Window 的高度。 Activity 高度会因为系统 chrome 而变短,例如状态栏和导航栏(在具有软件导航键的设备上)。
为了达到您想要的效果,您有两种选择:
1) 使用 getWindow().getDecorView()
的维度计算 window 的 "true middle"
2)(可能只适用于 21+)将 Activity 设置为全屏并具有稳定的布局:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
- 这将使您的内容与 window 的大小相同。
3) 等到布局在带有 alpha 动画的徽标视图中淡入淡出,而不是将其放入 window 背景
- 除非您的设计师真的抱怨,否则延迟可能不会造成任何伤害...
我正在创建一个带有图像的闪屏,并打算添加一个动画。所以我从这个开始 activity:
<activity
android:name=".activities.SplashActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这使用以下主题:
<style name="SplashTheme" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">@drawable/loading_page_4</item>
</style>
我正在使用它在布局呈现时立即显示图像。然后在 activity 的 onCreate 方法中,我设置了以下布局文件:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:foreground="@drawable/loading_page_4"
android:id="@+id/splash_color_layout" >
</FrameLayout>
出于某种原因,尽管是相同的可绘制对象,但在呈现页面时图像显示略有不同(它略微向下移动,甚至可能略微调整大小)。有没有一种方法可以使用相同的可绘制对象从主题背景无缝过渡到呈现的布局?
这里还有 activity class:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Splash screen view
setContentView(R.layout.activity_splash);
}
}
因此,这里的区别在于您的 Activity 的高度将不同于显示它的 Window 的高度。 Activity 高度会因为系统 chrome 而变短,例如状态栏和导航栏(在具有软件导航键的设备上)。
为了达到您想要的效果,您有两种选择:
1) 使用 getWindow().getDecorView()
2)(可能只适用于 21+)将 Activity 设置为全屏并具有稳定的布局:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
- 这将使您的内容与 window 的大小相同。
3) 等到布局在带有 alpha 动画的徽标视图中淡入淡出,而不是将其放入 window 背景
- 除非您的设计师真的抱怨,否则延迟可能不会造成任何伤害...