ImageButton and multiple screen sizes

  • Replies:3
Jason Wieczorek
  • Forum posts: 3

Jun 22, 2013, 9:13:36 PM via Website

Hi,

I am new to Android development and am working on my first app. I have an image for a button that I have placed in my drawable-xhdpi folder that is 240*100. While testing on multiple devices it seems to scale just fine. I feel this is not a good approach so I decided to create different sized images for each of the drawable folders to optimize the UI on a range of devices. I created a 150*63 image and placed it in the drawable-ldpi folder. To my shock, while testing the 150*63 image is drastically larger than the 240*100 image.

Can anyone explain why this is, it doesn't seem to make any sense?

Thanks in advance

Reply
KrayZ Logic
  • Forum posts: 17

Jun 23, 2013, 6:18:33 PM via Website

It could be a few things. How do you define the width and height of the button? Google also recommends using powers of 2 for images. So 256x128, 512x512, 128x32. I don't think the powers of 2 thing is causing your problem, but who knows. It's most likely being caused by something in your xml layout file or if you are adding the button from code, you need the correct layout params.

Reply
James Liu
  • Forum posts: 15

Jun 30, 2013, 5:45:18 PM via Website

As KrayZ Logic mentioned, how do you write your button in layout xml? Do you set the size there?

Reply
Jason Wieczorek
  • Forum posts: 3

Jul 20, 2013, 6:41:06 AM via Website

Hi,

Sorry for the late reply, dealing with a newborn and working full time is certainly taking time away from android dev!. I decided to start from scratch and first deal with mdpi only (because its the base dpi). Once I have everything in place, I plan to then deal with other screen sizes.

Current approach:
1. 'eyeball' my resources with the Graphical Layout from my IDE and adjust pixel size of resources until they are fitting the screen to my liking
2. once I am happy with layout, I will scale my resources based on the Scalars given by google docs and create the respective dpi and layout folders.

So far I feel this approach is working quite well.

Thoughts?

Jason

Reply