New UI-帶邊框的TextView,ui-textview

來源:互聯網
上載者:User

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設定邊框與圓角邊框,就介紹到這裡~






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.