Android在drawable资源文件中绘制圆形背景

首先看一下效果图:

这里写图片描述

shape可以绘制矩形环形以及椭圆、所以只需要用椭圆就可以完成需求、在使用的时候将控件比如textview的高宽设置成一样就是正圆、solid表示远的填充色、stroke则代表圆的边框线、所以两者结合可以实现带边缘的圆。

btn_background_round.xml文件代码

<? xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:useLevel="false">
    <solid android:color="@color/accent_material_light"></solid>
    <size
        android:width="15dp"
        android:height="15dp"></size>
    <padding
        android:bottom="1dp"
        android:left="2dp"
        android:right="2dp"
        android:top="1dp"></padding>

</shape>

引用代码

<LinearLayout
                android:id="@+id/ll_count_coming"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="50dp"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical">

                <TextView
                    android:layout_width="50dp"
                    android:layout_height="wrap_content"
                    android:background="@drawable/btn_background_round"
                    android:gravity="center"
                    android:paddingBottom="15dp"
                    android:paddingTop="15dp"
                    android:text="121" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:gravity="center"
                    android:text="已点到人数" />
            </LinearLayout>

希望对大家有用

  • 19
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值