我在我的应用程序上使用了一个主题,这样当它启动时,用户首先看到的是我的背景,而不是顶部带有操作栏的丑陋的黑色或白色屏幕。

<style name="LoadingTheme" parent="android:Theme.Holo.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/loading_home</item>
    </style>

足够简单。问题是,这个屏幕转换到我的启动页面/加载 Activity ,它显示相同的背景图像,但有一些缩放:
 <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitCenter"
        android:src="@drawable/loading_home"/>

我的问题是,在我的 Splash 页面(上面的 ImageView )中,背景按照我的意愿显示,因为它看起来没有拉伸(stretch)(我相信是由于 fitCenter)。但是,在我的应用程序样式中,背景变得拉伸(stretch)。有没有一种方法可以将 scaleType 应用于主题中的背景,或者另一种可以控制应用程序主题中背景图像缩放的方法?

最佳答案

尝试将您的 png 包装在一个 xml 文件中,并在样式中使用该 xml 作为 windowBackground,就像这样

window_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center"
android:src="@drawable/loading_home" />

样式.xml
<item name="android:windowBackground">@drawable/window_bg</item>

关于java - 将缩放类型更改为 fitCenter 以获取应用样式背景图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27911051/

10-12 00:36
查看更多