鸿蒙HarmonyOS APP开发入门3——组件(九 按钮组件 )—

本文介绍了如何在Android开发中使用胶囊按钮和圆形按钮创建拨号盘UI,详细展示了如何设置背景、尺寸和布局。同时提到了XML文件在定义图形元素中的作用。
摘要由CSDN通过智能技术生成

胶囊按钮是一种常见的按钮,设置按钮背景时将背景设置为矩形形状,并且设置ShapeElement的radius的半径,例如:

<Button ohos:id="$+id:button" 
 ohos:width="match\_content" 
 ohos:height="match\_content" 
 ohos:text\_size="27fp" 
 ohos:text="button" 
 ohos:background\_element="$graphic:capsule\_button\_element" 
 ohos:left\_margin="15vp" 
 ohos:bottom\_margin="15vp" 
 ohos:right\_padding="15vp" 
 ohos:left\_padding="15vp"/>

graphic目录下的capsule_button_element.xml文件示例如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos" 
 ohos:shape="rectangle">    
    <corners ohos:radius="100"/>
    <solid ohos:color="#007CFD"/>
</shape>

圆形按钮

img

圆形按钮和椭圆按钮的区别在于组件本身的宽度和高度需要相同,例如:

<Button 
 ohos:id="$+id:button" 
 ohos:width="50vp" 
 ohos:height="50vp" 
 ohos:text\_size="27fp" 
 ohos:background\_element="$graphic:circle\_button\_element" 
 ohos:text="+" ohos:left\_margin="15vp" 
 ohos:bottom\_margin="15vp" 
 ohos:right\_padding="15vp" 
 ohos:left\_padding="15vp"/>

graphic目录下的circle_button_element.xml文件示例如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos" 
 ohos:shape="oval">    
    <solid ohos:color="#007CFD"/>
</shape>

场景示例

利用圆形按钮,胶囊按钮,文本组件可以绘制出如下拨号盘的UI界面。

**图4 界面效果

img

源码示例:
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
 xmlns:ohos=&#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值