Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android TextView 圓弧邊框與背景實作詳解

編輯:關於 Android 程式設計

Android TextView 圓弧

效果圖:

布局碼:

 <TextView android:id="@+id/product_tag" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:singleLine="true" android:textSize="10sp" android:textColor="@color/label_orange" android:layout_marginLeft="10dp" android:background="@drawable/shape_label_orange" android:text="標簽"/> 

樣式碼:弧度與背景主要靠 background 中的 xml 檔實現。

1、圓角矩形樣式:

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="https://schemas.android.com/apk/res/android"> <!-- 實心 --> <solid android:color="@android:color/white"/> <!-- 邊框 --> <stroke android:width="0.5dp" android:color="@color/label_orange"/> <!-- 圓角 --> <corners android:radius="3dp"/> <!-- 邊距 --> <padding android:top="2dp" android:bottom="2dp" android:left="6dp" android:right="6dp"/> </shape> 

2、橢圓樣式:

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="https://schemas.android.com/apk/res/android" android:shape="oval" android:useLevel="false"> <!-- 實心 --> <solid android:color="@color/label_round_orange" /> <!-- 圓角 --> <corners android:radius="360dp" /> <!-- 邊距 --> <padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" /> <!-- 大小 --> <size android:width="15dp" android:height="15dp" /> </shape> 

透過 shape 標籤的 solid(實心)、stroke(邊框)、corners(圓角)與 padding(邊距),即可輕鬆做出圓角標籤或圓形背景。希望這份整理能幫助到你。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved