android shape画边框,安卓用shape画圆角矩形边框

效果图:

8fa45d04ff37?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

代码:

一、xml方式

代码: shape_rec_blue.xml

圆角矩形边框

android:shape="rectangle">

android:width="1dp"

android:color="#418DF9" />

8fa45d04ff37?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

圆角矩形背景

android:shape="rectangle">

8fa45d04ff37?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

使用

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#F3F3F3"

android:orientation="vertical">

android:id="@+id/ll_bottom_split"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/shape_rec_blue"

android:layout_margin="10dp"

android:layout_gravity="center"

android:orientation="horizontal">

android:layout_height="wrap_content"

android:textSize="30dp"

android:text=" 测试测试测试测试 "/>

二、kotlin方式

代码

圆角矩形边框

private fun getRoundRectStroke() = GradientDrawable().also {

it.shape = GradientDrawable.RECTANGLE

it.cornerRadius = 10f //圆角度数

val strokeWidth = 4 // 边框宽度

val strokeColor = Color.parseColor("#418DF9") //边框颜色

it.setStroke(strokeWidth, strokeColor)

}

圆角矩形背景

private fun getRoundRect() = GradientDrawable().also {

it.shape = GradientDrawable.RECTANGLE

it.cornerRadius = 10f

it.setColor(Color.parseColor("#418DF9"))

}

使用方法

view.background = getRoundRect()

附录:

8fa45d04ff37?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值