我如何编程圆一个按钮,Android的? [英] How do I round a button programmatically in Android?

查看:189
本文介绍了我如何编程圆一个按钮,Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮使用自定义适配器的号召, getView其中填充一个 GridView控件 ()。因此,没有为按钮没有.xml文件

I have a Button which populates a GridView using a custom adapter's call to getView(). As such, there is no .xml file for the Button.

有没有一种方法以编程方式圆按钮

Is there a way to programmatically round the Button?

推荐答案

使用九补丁,下面是一个例子之一:

Use a nine patch, here is an example one:

它保存在你的 / RES /绘-MDPI / 与文件名目录 btn_round.9.png

save this in your /res/drawable-mdpi/ directory with the filename btn_round.9.png

然后在你的java code做到这一点:

then in your java code do this:

mBtn.setBackgroundResource(R.drawable.btn_round);

因为它是9补丁机智将延伸到适合任何内容您的按钮内推杆。搜索机器人draw9patch来了解更多关于如何创建9补丁文件。

because it is 9 patch wit will stretch to fit whatever content you are putting inside the button. Search for "android draw9patch" to learn more about how to create the 9 patch files.

这篇关于我如何编程圆一个按钮,Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆