歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android shap 控件美化

Android shap 控件美化

日期:2017/3/1 9:36:07   编辑:Linux編程

Android中我們一般通過給控件設置png圖片來改變控的外觀,shap也能定義簡單的圖形來完成同樣的的功能。

shap在drawable目錄下,根節點為shap。

1.圓形或者橢圓形

android:shape="oval" 橢圓

solid 顏色

控件長寬相等時顯示圓,不相等時橢圓

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >

<solid android:color="#55000000" />

</shape>

使用時與drawable下的資源方式相同

<TextView
android:id="@+id/textview1"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/textview_bg" />

2.圓角矩形
android:shape="rectangle" 矩形

corners 半徑,可以分別對四個角設半徑

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<corners
android:bottomLeftRadius="10dip"
android:bottomRightRadius="10dip"
android:topLeftRadius="10dip"
android:topRightRadius="10dip" />

<solid android:color="#55000000" />

</shape>

3.漸變

gradient漸變

startColor 起始顏色

endColor 結束顏色

angle 漸變角度

padding 與控件邊緣的距離

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFF0000"
android:endColor="#80FF00FF"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />

</shape>

4.邊框效果

stroke 邊框,可以設置顏色和寬度

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<corners
android:bottomLeftRadius="10dip"
android:bottomRightRadius="10dip"
android:topLeftRadius="10dip"
android:topRightRadius="10dip" />

<solid android:color="#55000000" />

<stroke android:width="4dip"
android:color="@android:color/white"/>
</shape>

5.圓環效果

就是shape="oval" 橢圓 加上 stroke邊框

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >

<corners
android:bottomLeftRadius="10dip"
android:bottomRightRadius="10dip"
android:topLeftRadius="10dip"
android:topRightRadius="10dip" />

<solid android:color="#55000000" />

<stroke android:width="4dip"
android:color="@android:color/white"/>
</shape>

最簡單的Ubuntu Touch & Android 雙系統安裝方式 http://www.linuxidc.com/Linux/2014-01/94881.htm

在Nexus上實現Ubuntu和Android 4.4.2 雙啟動 http://www.linuxidc.com/Linux/2014-05/101849.htm

Ubuntu 14.04 配置 Android SDK 開發環境 http://www.linuxidc.com/Linux/2014-05/101039.htm

64位Ubuntu 11.10下Android開發環境的搭建(JDK+Eclipse+ADT+Android SDK詳細) http://www.linuxidc.com/Linux/2013-06/85303.htm

Ubuntu 14.04 x64配置Android 4.4 kitkat編譯環境的方法 http://www.linuxidc.com/Linux/2014-04/101148.htm

Ubuntu 12.10 x64 安裝 Android SDK http://www.linuxidc.com/Linux/2013-03/82005.htm

更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11

Copyright © Linux教程網 All Rights Reserved