0

我的应用程序中有很多按钮,它们的大小根据里面的文本而有所不同。我想自定义按钮,但我不确定是否应该使用

A) Ninepatch pngs

B)创建的Android xml

C) Photoshop png

我希望按钮可以很好地缩放,因此不会因屏幕尺寸而变形。上述方法的优缺点是什么?有没有理想的方法来解决这个问题?

4

1 回答 1

1

It depends on what they should look like. Rounded corners? Complicated images? Drop shadows? Plain colors?

If you want simple buttons that are monotone in color, xml drawables are the best solution. You can do rounded corners through xml, so if plain is what you are looking for this is the best option.

If you are working with an image, then a 9 patch is the way to go. Play around with the draw9patch tool that comes with the sdk to get the hang of it. You also don't necessarily only need to leave the corners in tack, sometimes you may want to break up the resizable area depending on the image.

PNGs are the last resort as they are the least flexible of the 3 options.

By the way, you should also consider using a state list for all of your buttons, regardless of how you implement the drawable that the button uses. See the link below:

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

于 2012-07-01T16:37:02.073 回答