ANDROID SHAPE畫圓形背景實現圓形TextView

shape可以繪製矩形環形以及橢圓、所以只需要用橢圓就可以完成需求、在使用的時候將控件比如textview的高寬設置成一樣就是正圓、solid表示遠的填充色、stroke則代表遠的邊框線、所以兩者結合可以實現帶邊緣的圓、Shape 代碼

<?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/base_color" />
  <padding
    android:left="2dp"
    android:top="1dp"
    android:right="2dp"
    android:bottom="1dp" />
  <solid
    android:color="@color/green" />
  <stroke
    android:width="1dp"
    android:color="@android:color/white" />
  <size android:width="25dp"
    android:height="25dp" />
</shape>
把以上代碼添加到drawable裏面、通過background引用就可以了

<TextView
        android:id="@ id/message_category_unread_count"
        style="@style/comm_text_style_14_aaaaaa"
        android:layout_marginLeft="70dp"
        android:layout_marginTop="5dp"
        android:background="@drawable/design_red_point"
        android:gravity="center"
        android:textSize="@dimen/text_size_comment_20"
        android:text="7"
        android:textColor="@android:color/white" />

原文: http://unix8.net/home.php/android-shape畫圓形背景實現圓形textview.html

發佈了104 篇原創文章 · 獲贊 86 · 訪問量 26萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章