Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change scale type to fitCenter for app style background image

Tags:

java

android

I am using a theme on my application so that when it start's up, the first thing a user sees is my background instead of an ugly black or white screen with an action bar on top.

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

Simple enough. The problem is that, this screen transitions into my Splash page/Loading activity, which is displaying the same background image but with some scaling:

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

My issue is, that in my Splash page (the image view above), the background is displaying as I would like it, in that it does not look stretched (I believe due to fitCenter). However, in my application style, the background becomes stretched. Is there a way that I can apply scaleType to a background in a theme, or another method in which I can have control over the scaling of the background image in my application theme?

like image 801
stevebot Avatar asked Sep 06 '25 20:09

stevebot


1 Answers

Try to wrap your png in a xml file, and use the xml as windowBackground in the style, like so

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>
like image 186
Joao Sousa Avatar answered Sep 10 '25 13:09

Joao Sousa