New UI-帶邊框的TextView,ui-textview
New UI-帶邊框的TextView
——轉載請註明出處:coder-pig,歡迎轉載,請勿用於商業用途!
小豬Android開發交流群已建立,歡迎大家加入,無論是新手,菜鳥,大神都可以,小豬一個人的
力量畢竟是有限的,寫出來的東西肯定會有很多紕漏不足,歡迎大家指出,集思廣益,讓小豬的博文
更加的詳盡,幫到更多的人,O(∩_∩)O謝謝!
小豬Android開發交流群:小豬Android開發交流群群號:421858269
新Android UI執行個體大全目錄:http://blog.csdn.net/coder_pig/article/details/42145907
本節引言:
本節介紹的是為TextView設定一個邊框背景,常用的邊框有矩形與圓角矩形!
另外,因為TextView是很多其他UI控制項的父類,比如Button,也可以設定這樣的圓角
矩形邊框!實現的原理也很簡單,就是我們自行編寫一個shape的資源檔!
然後TextView直接設定blackground等於這個資源檔即可!
本節本文:
引言裡已經說了,關鍵是編寫shape的資源檔,那我們先來看以下幾個節點與屬性:
<solid android:color = "xxx"> 這個是設定背景顏色的
<stroke android:width = "xdp" android:color="xxx"> 這個是設定邊框的粗細,以及邊框顏色的
<padding androidLbottom = "xdp"...> 這個是設定邊距的
<corners android:topLeftRadius="10px"...> 這個是設定圓角的
<gradient> 這個是設定漸層色的,可選屬性有:
startColor:起始顏色 endColor:結束顏色 centerColor:中間顏色
angle:方向角度,等於0時,從左至右,然後逆時針方向轉,當angle = 90度時從下往上
type:設定漸層的類型
接下來我們就來實際應用下:
1.編寫矩形邊框的shape:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 設定一個藍色邊框 --> <stroke android:width="2px" android:color="#07387B"/> <!-- 漸層 --> <gradient android:angle="270" android:endColor="#C0C0C0" android:startColor="#A020F0" /> <!-- 設定一下邊距,讓空間大一點 --> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp"/> </shape>
2.編寫圓角矩形邊框的shape:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 設定透明背景色 --> <solid android:color="#87CEEB" /> <!-- 設定一個綠色邊框 --> <stroke android:width="2px" android:color="#000000" /> <!-- 設定四個圓角的半徑 --> <corners android:bottomLeftRadius="10px" android:bottomRightRadius="10px" android:topLeftRadius="10px" android:topRightRadius="10px" /> <!-- 設定一下邊距,讓空間大一點 --> <padding android:bottom="5dp" android:left="5dp" android:right="5dp" android:top="5dp" /></shape>
啟動並執行:
恩,關於如何為TextView設定邊框與圓角邊框,就介紹到這裡~