开发者

Android: Scaling image offsets between resolutions

I have an app where, in landscape, I line up a bunch of lowercase alphabet ImageView pngs so that they are sitting on an imaginary line. The problem is that they are of different heights i.e. an 'h' is taller than an 'a'. Thus I've been setting the android:layout_marginTop attribute for each letter, in pixels, to line them up on the Galaxy Tab. This has worked.

My problem is that when I go to run the app on a Milestone, the scaling of the offsets is a litttttle 开发者_StackOverflow中文版wonky. It looks like there's some sort of scaling happening, which is kind of working, but it's not perfect. Anyone have an idea how I could remedy this?


I think that trying to hard code the offsets for each letter and each display resolution is going to be a real pain and will be even bigger pain to maintain.

An easy solution would be to use photoshop (or gimp) to resize the png files so they all have the exact same dimensions and set the new region of the PNG to be transparent.


I would first question why you're doing it this way...seems overly complicated. That said, you could try to just measure the maximum heigh for the ImageViews and use that. For example, x, h, and g all have the same x-height (the height of the lowercase letter x) but the h has an ascender, and the g has a descender (which go above and below the standard x-height respectively). You could create all the letters aligned on the baseline, give them all the same height (the x-height + the ascender height + the descender height) and then just align top, bottom, or center align them on the imaginary line, which should give you a proper alignment.

Really, if you can share a little more information (a screenshot maybe?) there's probably a much more elegant solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜