开发者

Layout that enlarges buttons for larger screens?

开发者 https://www.devze.com 2023-02-21 10:02 出处:网络
When specifying the size of buttons and toolbars, I\'ve been using the \"device independent pixels\" (dip) feature of the XML layout files. By using dips, I can specify the physical size of the GUI co

When specifying the size of buttons and toolbars, I've been using the "device independent pixels" (dip) feature of the XML layout files. By using dips, I can specify the physical size of the GUI components, which is good for ensuring components are always readable and clickable for all screen sizes. For example, my app has a horizontal toolbar that is about 50dip high at the top with several 40dipx40dip buttons along it.

However, buttons whose开发者_Python百科 physical size is just big enough to see and click on for a small screen aren't very usable on tablets. For example, my toolbar will contain huge amounts of whitespace, the buttons are hard to see (as you tend to hold the tablet further away from your face) and the buttons are hard to click on in practice (as they are small proportional to the screen)

Are there any resolution independent approaches for dealing with this?

I know I can use "layout_weight" to stretch components so I can specify what percent of the screen to use but this is going to be really cumbersome for lots of buttons (also, my buttons need to be square) if I have to do this mostly manually. I can use different layout files for each device, but this is a pain.


Are there any resolution independent approaches for dealing with this?

Use dimension and drawable resources.

You haven't indicated how your buttons are "40dipx40dip".

If they are set that way via specific heights and widths, instead of having 40dip in a layout or in a style, use @dimen/toolbar_btn. Then in res/values/dimens.xml define that to be 40dip and in res/values-large/dimens.xml (or maybe res/values-large-land/dimens.xml) define that to be, say, 60dip, or whatever works for you.

If the buttons are "40dipx40dip" because of images, then it's merely a matter of creating somewhat larger images for tablets and putting them in, say, res/drawable-large-mdpi/ resource directory.

0

精彩评论

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

关注公众号