我该如何做一个左/右圆角为圆形的按钮 [英] How I can do a button with left/right side as rounded as circle

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

问题描述

我正在尝试将按钮的侧面修圆,但是当我更改屏幕尺寸时,将按钮的左侧修圆为圆形,这并不能保持宽高比(我认为).

I'm trying to do a button with the sides rounded, but when I change the size of screen the button sides left to be rounded as circles, doesn't mantain the aspect ratio (I think).

我想要每个尺寸的下一个切换按钮.如何针对每种分辨率将XML进行四舍五入?

I want to have the next togglebutton in everysize. How I can do an XML with the sides rounded for every resolution?

我已经读过这篇文章,但这不是解决方案(如何使按钮的角变圆?)

I've read this, but is not a solution (How to make the corners of a button round?)

推荐答案

其他答案都是正确的...差不多: 如果您将角设置为某个值(例如20dp),但是您的按钮高度会更大(例如40dp)-您将以圆角而不是圆边结束.因此,解决方案很简单:将android:corners属性设置为足够高的值,该值将大于按钮的高度:

The other answers are correct... almost: if you will set corners to some value (let's say 20dp), but your button height will be greater (like 40dp) - you will end with rounded corners instead of rounded sides. The solution is thus straightforward: set android:corners attribute to some high enough value that will be greater than button height:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/colorPrimary" />
    <corners android:radius="200dp" />
    <size
        android:height="16dp"
        android:width="32dp" />
</shape>

这篇关于我该如何做一个左/右圆角为圆形的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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