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>

希望对大家有用

猜你喜欢

转载自blog.csdn.net/zjy_android/article/details/79483615