Discussion Forums  >  Images, Documents, File Locations

Replies: 10    Views: 734

Fateful
I hate code!
Profile
Posts: 8
Reg: Feb 09, 2012
Black Mountain
2,980
09/06/12 07:34 AM (13 years ago)

Android background images always scale up

My app contains rulers that need to be exactly to scale when viewed in order to be accurate. When I compiled the app for Xcode, I simply set blank screens with a centered background image. This worked great for Xcode...no up-scaling. But when I try the same for Android, the emulator always scales the background image up to fill the screen. Is there any way of stopping this from occurring?
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
09/06/12 08:47 AM (13 years ago)
Hi @Fateful, Welcome to buzztouch! So, are you saying that, in the Advanced Properties for that screen where you set the background image name, you have set the "Background Image Scale / Position" to something other than Full Screen, and it's still scaling them to fill the screen? Mark
 
Fateful
I hate code!
Profile
Posts: 8
Reg: Feb 09, 2012
Black Mountain
2,980
like
09/06/12 09:01 AM (13 years ago)
Yes, that is correct. I set the "Scale/Position" to center, which seems to work fine in iOS. But on Android, the background drawable is always stretched to fill the screen. I've tried to adjust the RelativeLayout for the layout resource "screen_blank.xml" in Eclipse to have fixed dimensions in @+id/containerView's layout_width and layout_height instead of "wrap_content" or "fill_parent", but the drawable is still stretched to fill the screen. I've also tried density-independent pixels, but the problem persists.
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
09/06/12 09:03 AM (13 years ago)
Interesting. Let me see if I can get David to check this out. He might know of a code issue. Mark
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/06/12 10:30 AM (13 years ago)
Something is screwy, image should not scale if center is selected. Could a setting in theme be overriding a setting for one screen? The image does not get set in the XML layout for "each "screen, you won't see it in individual layout files. It's using the layout file from the "base" class. Background is "behind" each screens XML layout file.
 
Fateful
I hate code!
Profile
Posts: 8
Reg: Feb 09, 2012
Black Mountain
2,980
like
09/06/12 10:40 AM (13 years ago)
I have background image set to "center" in theme too. In fact, if I define a background image in the theme console, it too gets stretched. Is there something I can adjust in the base class to control re-sizing background images?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/06/12 03:47 PM (13 years ago)
Assuming you're buzztouch v2.0....a brief explanation on how it works....then some ideas.. --Each screen (java Activity class) is a sub-class of BT_activity_base. --BT_activity_base loads a layout.xml file on line 151. This file is called "act_base.xml" and it's the layout file that's behind everything on each screen. Have a look at act_base.xml in an editor. You'll see series of RelativeLayout objects defined in XML. The one your interested in has an id of "backgroundImageBox". This layout has a child widget called backgroundImageView. You'll see that this ImageView has some hard code height / width values in the XML: fill_parent. --So that's the setup. Next, when each screen is displayed (each Activity), it runs a method called updateBackgroundColorsForScreen. This method is triggered in every screen's onCreate method. This method does all sorts of stuff, including setting the image for the background, and determining how to size / scale it. All it does is alter the scale property of the ImageView containing the background. It's necessary to do this because the layout has defined "fill_parent" and in many cases "fill_parent" is not appropriate. I would suggest digging around a bit, trying to get your head around all the parts, and reviewing the relationship between each piece before hacking anything up. Or...what the heck, hack away, you can always get a new copy :-) These concepts don't explain they the ImageView for the background appears to be scaling your image when it should center it. LOTS of these exist and I've not heard this before. Could it be that your image is simply larger than you think? Dunno.
 
Fateful
I hate code!
Profile
Posts: 8
Reg: Feb 09, 2012
Black Mountain
2,980
like
09/07/12 07:17 AM (13 years ago)
Okay, first the good news...BuzzTouch appears to do what it intends to here! I'm beginning to wonder if there is an issue with the emulator and how it scales background images though. I downloaded a fresh batch of source code from BT and included a small black rectangle png as a centered background image for a blank screen. The image has a resolution of 160dpi, as does the emulator skin I'm using. I have set the emulator to "scale display to real size", making sure my monitor size and resolution are entered correctly and creating an emulator screen size ample enough to contain my black rectangle. The emulator appears to be exactly doubling the image size. I have tried adjusting the ImageView containing the background (in act_base.xml) to "wrap_content", to the precise metric dimension I want the image, and to dip dimensions based on the images pixel dimensions. In every instance the emulator appears to exactly double the image size. I believe I've set the "scale display to real size" settings on the emulator correctly. The emulator screen size measures true to whatever I set it at. Have you ever heard of similar issues with the AVD? Unfortunately I don't have a real device to test on right now.
 
Fateful
I hate code!
Profile
Posts: 8
Reg: Feb 09, 2012
Black Mountain
2,980
like
09/07/12 07:54 AM (13 years ago)
Moreover, if I set the "scale display to real size" settings to my monitor's specs, but adjust the AVD's real screen size up or down, the centered background image scales up or down proportionally. Something screwy with the AVD. Am I missing an emulator setting?
 
Fateful
I hate code!
Profile
Posts: 8
Reg: Feb 09, 2012
Black Mountain
2,980
like
09/17/12 01:20 PM (13 years ago)
From what I've read about how Android handles bitmaps, the default is for there to be some pre-scaling to images. Apparently you can override this default at the point where the bitmap is created by defining inDensity and inScaled options. Can I ask where in the BT source code I would define these options for the background image when it is created?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/17/12 01:34 PM (13 years ago)
Hmm...haven't worked with inDensity or inScaled. But, surely this would be configured in the source code that sets the image, like you mentioned. This would be done in the BT_activity_base.java file, in the updateBackgroundColorsForScreen() method.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.