android shape的使用及漸變色、分割線、邊框、半透明陰影
shape使用、漸變色、分割線、邊框、半透明、半透明陰影效果。
首先簡(jiǎn)單了解一下shape中常見的屬性。(詳細(xì)介紹參看 api文檔)
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape=["rectangle" | "oval" | "line" | "ring"] > --- 默認(rèn)為rectangle <corners -- shape=“rectangle”時(shí)使用, android:radius="integer" -- 半徑,會(huì)被下邊的屬性覆蓋,默認(rèn)為1dp, android:topLeftRadius="integer" android:topRightRadius="integer" android:bottomLeftRadius="integer" android:bottomRightRadius="integer" /> <gradient -- 漸變 android:angle="integer" android:centerX="integer" android:centerY="integer" android:centerColor="integer" android:endColor="color" android:gradientRadius="integer" android:startColor="color" android:type=["linear" | "radial" | "sweep"] android:useLevel=["true" | "false"] /> <padding android:left="integer" android:top="integer" android:right="integer" android:bottom="integer" /> <size -- 指定大小,一般用在imageview配合scaleType屬性使用。大小一般會(huì)適配滴 android:width="integer" android:height="integer" /> <solid -- 填充顏色,可是是十六進(jìn)制顏色。(比如想設(shè)置半透明效果,直接使用十六就只就OK) android:color="color" /> <stroke -- 指定邊框,border,dashWidth和dashGap有一個(gè)為0dp則為實(shí)線 android:width="integer" android:color="color" android:dashWidth="integer" -- 虛線寬度 android:dashGap="integer" /> -- 虛線間隔寬度 </shape>
注意:
<corners>
1、android:radius,半徑,會(huì)被下邊的單個(gè)角度半徑屬性覆蓋,默認(rèn)為1dp,
2、在使用時(shí),如果單獨(dú)設(shè)置四個(gè)角度,又大小不一致時(shí),eclipse的graphics preview會(huì)報(bào)錯(cuò)。但是直接真機(jī)運(yùn)行即可。(比如實(shí)線上邊直角,下邊屈角的效果)
<size>
Note: The shape scales to the size of the container View proportionate to the dimensions defined here, by default. When you use the shape in an ImageView
, you can restrict scaling by setting the android:scaleType
to "center"
舉個(gè)栗子:
1、漸變色 res/drawable/gradient_box.xml
:
<?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>
如圖:
2、白色邊框、半透明效果
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="16dp" /> <!-- 這是半透明,還可以設(shè)置全透明,那就是白色邊框的效果了 --> <solid android:color="#80065e8d" /> <stroke android:dashGap="0dp" android:width="4dp" android:color="@android:color/white" /> </shape>
如圖:
3、分割線效果:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" > <stroke android:width="4dp" android:color="@android:color/black" /> </shape>
如圖:
4、單邊屈角效果
<?xml version="1.0" encoding="utf-8"?> <shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" android:bottomLeftRadius="30dp" android:bottomRightRadius="30dp"/> <!-- 這是半透明,還可以設(shè)置全透明,那就是白色邊框的效果了 --> <solid android:color="#ff065e8d" /> <stroke android:dashGap="0dp" android:width="4dp" android:color="@android:color/white" /> </shape>
如圖:
另:附上一份顏色進(jìn)制圖,需要的可以查閱:http://tools.jb51.net/static/colorpicker/index.html
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android獲取手機(jī)的版本號(hào)等信息的代碼
這篇文章主要為大家詳細(xì)介紹了Android獲取手機(jī)的版本號(hào)等信息的代碼,代碼很精彩,感興趣的小伙伴們可以參考一下2016-07-07android studio 新手入門教程(二)項(xiàng)目的導(dǎo)入教程圖解
這篇文章主要介紹了android studio 新手入門教程(二)項(xiàng)目的導(dǎo)入教程圖解,需要的朋友可以參考下2017-12-12Android開發(fā)實(shí)現(xiàn)在Wifi下獲取本地IP地址的方法
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)在Wifi下獲取本地IP地址的方法,涉及Android編程Wifi的調(diào)用及IP地址的獲取與轉(zhuǎn)換相關(guān)操作技巧,需要的朋友可以參考下2017-09-09Android RetainFragment狀態(tài)保存的方法
本篇文章主要介紹了Android RetainFragment狀態(tài)保存的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-02-02Android實(shí)現(xiàn)ImageView圖片雙擊放大及縮小
這篇文章主要介紹了Android實(shí)現(xiàn)ImageView圖片雙擊放大及縮小的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-02-02Android實(shí)現(xiàn)按鈕點(diǎn)擊事件的三種方法總結(jié)
Button是程序用于和用戶進(jìn)行交互的一個(gè)重要控件。既然有Button,那肯定有onClick方法,下面就教大家三種實(shí)現(xiàn)點(diǎn)擊事件的方法,感興趣的可以了解一下2022-04-04