Android开发设置button形状之圆角、椭圆、矩形

button的形状描述文件drawable/shape.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape 
    xmlns:android="http//schemas.android.com/apk/res/android" 
    android:shape="oval"> 
    <!-- 填充的颜色 --> 
    <solid android:color="#BFBFBF" />
    <!-- 设置按钮的四个角为弧形 --> 
    <!-- android:radius 弧形的半径 --> 
    <corners android:radius="25dip" /> 
      
<!-- padding:Button里面的文字与Button边界的间隔 --> 
<padding 
   android:left="10dp" 
   android:top="10dp" 
   android:right="10dp" 
   android:bottom="10dp" 
/> 
<!-- corners :Button四周为圆角,不需要的可以删除此项 --> 
<corners android:radius="100dp">
</corners>
</shape>


在布局文件中layout.xml中对shape.xml的引用语句,用来设置button形状:

      <Button android:id="@+id/yes"
          android:text="@string/yes"
          android:background="@drawable/shape"> 
      </Button>

解析shape文件中的android:shape属性:
Android:shape=[“rectangle” | “oval” | “line” | “ring”]

其中rectagle矩形,oval椭圆,line水平直线,ring环形

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章