圆形按钮的实现

    xiaoxiao2021-12-13  57

    1.正圆形

    第一种,用xml作为background来实现圆形按钮

    效果图;

    首先,在布局里放一个按钮

    <Button android:id="@+id/main2_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="圆形按钮" android:layout_gravity="center|bottom" android:gravity="center" android:background="@drawable/yuanxing_btn"/> 然后写一个xml文件放在drawable文件夹下,

    <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <!-- shape取值有四种,可以是rectangle(长方形),oval(椭圆),line(线条),ring(圆环), --> <solid android:color="#ff0000" /> <size android:width="100dp" android:height="100dp"/> <!-- oval是椭圆,所以宽高一样才能做出圆形的效果 --> </shape>

    以上只是一种实现方式,未完待续--------

    2.两端圆形的按钮

    效果图:

    也是用xml实现的,

    <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ffffff"/><!--背景颜色--> <stroke android:width="1dp" android:color="#55000000"/><!-- stroke描边,描边宽度,颜色--> <corners android:radius="30dp"/><!--corners圆角,radius半径--> <padding android:bottom="5dp" android:top="5dp" android:left="20dp" android:right="20dp" /> <!-- 设置文字和各个方向的间隔 --> </shape> 然后在布局文件中引用这个文件作为背景就行了

    android:background="@drawable/yuanjiao_button"

    转载请注明原文地址: https://ju.6miu.com/read-950298.html

    最新回复(0)