首页 文章

将比例类型更改为适用于app风格背景图像的fitCenter

提问于
浏览
2

我在我的应用程序上使用了一个主题,以便当它开始时,用户看到的第一件事是我的背景,而不是一个丑陋的黑色或白色屏幕,顶部有一个操作栏 .

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

很简单 . 问题是,这个屏幕转换到我的Splash页面/加载活动,它显示相同的背景图像,但有一些缩放:

<ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitCenter"
        android:src="@drawable/loading_home"/>

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

1 回答

  • 3

    尝试将你的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" />
    

    styles.xml

    <item name="android:windowBackground">@drawable/window_bg</item>
    

相关问题