【发布时间】:2014-08-08 19:36:15
【问题描述】:
我不知道该怎么称呼它……也许是药丸状的。谷歌搜索圆角会发现很多人想要一个带圆角的矩形按钮。这有点不同,但更像是我尝试将其绘制成的 2 个圆圈和一个矩形。
我想通过在 android 上使用 xml 可绘制背景制作一个类似于下面第一张图片的按钮,但其中包含文本和图标图片:
我试过这个,看起来不错,但是如果按钮长度不同,它就不会缩放,你最终会得到一个矩形和一些其他奇怪的东西。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="40dp" android:top="0dp" android:bottom="0dp">
<shape android:shape="oval" >
<solid android:color="#666666"/>
<size android:width="40dp" android:height="40dp"></size>
</shape>
</item>
<item android:left="20dp" android:right="20dp">
<shape android:shape="rectangle" >
<solid android:color="#666666"/>
<size android:width="20dp" android:height="20dp"></size>
</shape>
</item>
<item android:right="40dp">
<shape android:shape="oval" >
<solid android:color="#666666"/>
<size android:width="40dp" android:height="40dp"></size>
</shape>
</item>
</layer-list>
我也尝试过像这样创建我的 xml 可绘制对象:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#666666" />
<corners android:radius="20dp"/>
<size android:height="20dp" android:width="60dp"></size>
</shape>
看起来像这样:
我查看了this persons example,但是当我按照他的方式进行操作时,我的结果并没有完全圆润。它们更像上面的第二张图片。
【问题讨论】:
-
你试过弄乱你的半径值吗?这就是外观的决定因素。
-
我知道您想使用 xml 来创建您的按钮,但我认为正确的方法是使用 NinePatch 图像。
-
你能把第二个的整个xml贴出来吗
-
@twhite 是的,请参阅第二个 xml 块。
-
@Larry 我宁愿不使用九个补丁。
标签: android button user-interface android-drawable