国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android利用shape實(shí)現(xiàn)各種簡單的形狀

2019-10-23 18:27:47
字體:
供稿:網(wǎng)友

一,概述

我們在android/245951.html">android開發(fā)中經(jīng)常要用到圖片,而一些簡單的圖片我們完全可以用shape形狀drawable資源代替,使用shape有一個(gè)好處就是可以減小我們apk的大小,因?yàn)橥瑯拥男Ч瑂hape比圖片更節(jié)省空間,好了,我們廢話不多說,下面進(jìn)入正題。

二,shape初識(shí)

shape是android drawable資源中的一個(gè)重要的角色,drawable資源覆蓋面廣,它不僅代表圖片,它可以是一個(gè)顏色,一個(gè)形狀,因?yàn)閟hape其簡單實(shí)用,下面我們來看一下shape形狀的分類:

ectangle:

rectangle代表者矩形,它是shape默認(rèn)的形狀類型,即如果我們不在shape的android:shape屬性指定其類型時(shí),默認(rèn)是矩形,用它我們可以畫一個(gè)矩形,圓角矩形,具體在下面會(huì)說道

oval:

ovel,橢圓,用它可以畫橢圓,圓

line:

水平線,在使用該形狀的時(shí)候,我們得給它指定stroke元素指定其寬度,不然在使用該形狀的時(shí)候會(huì)報(bào)空指針異常

ring:

環(huán)形

下面我們來用上面說道的各種形狀畫圖形,打造各種簡單的形狀

三,shape的使用

下面看看用shape畫的一些簡單的圖形,之后我會(huì)按照圖形說一下shape的各種屬性以及一些要注意的問題:

android,shape使用,android中shape的使用,shape的使用

1.實(shí)心長方形

<shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 設(shè)置固定填充色 --> <solid android:color="#f00" /> <size android:width="60dp" android:height="30dp"/></shape>

2.炫彩實(shí)心長方形

<shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="rectangle"> <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置漸變填充色 --> <gradient android:startColor="#00f" android:centerColor="#0f0" android:endColor="#f00"></gradient></shape>

3.長方形外框

<shape xmlns:android="http://schemas.android.com/apk/res/android" > <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置描邊 --> <stroke android:width="2dp" android:color="#f00" ></stroke></shape>

4.虛線長方形外框

<shape xmlns:android="http://schemas.android.com/apk/res/android" > <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置描邊 --> <stroke android:width="2dp" android:color="#f00" android:dashWidth="5dp" android:dashGap="5dp"></stroke></shape>

5.橢圓虛線外框

<shape xmlns:android="http://schemas.android.com/apk/res/android" > <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置描邊 --> <stroke android:width="2dp" android:color="#f00" android:dashWidth="5dp" android:dashGap="5dp"></stroke> <corners android:radius="15dp"/></shape>

6.實(shí)心長方體切圓角

<shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 設(shè)置固定填充色 --> <solid android:color="#f00" /> <size android:width="60dp" android:height="30dp"/> <corners android:radius="10dp"/></shape>

7.

<shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="rectangle"> <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置漸變填充色 --> <gradient android:startColor="#f00" android:centerColor="#0f0" android:endColor="#00f" android:gradientRadius="60" android:type="radial"></gradient></shape>

8.

<shape xmlns:android="http://schemas.android.com/apk/res/android" > <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置描邊 --> <stroke android:width="2dp" android:color="#f00" ></stroke> <corners android:radius="15dp"/></shape>

9.

<shape xmlns:android="http://schemas.android.com/apk/res/android"  > <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置漸變填充色 --> <gradient android:startColor="#f00" android:centerColor="#0f0" android:endColor="#00f" android:type="sweep"></gradient></shape>

10.

<shape xmlns:android="http://schemas.android.com/apk/res/android" > <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置描邊 --> <stroke android:width="2dp" android:color="#f00" android:dashWidth="5dp" android:dashGap="5dp"></stroke> <corners android:radius="15dp" android:topRightRadius="0dp" android:bottomRightRadius="0dp"/></shape>

11.

<shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="oval"> <!-- 設(shè)置固定填充色 --> <solid android:color="#f00" /> <size android:width="60dp" android:height="30dp"/></shape>

12.

<shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="oval"> <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置漸變色 --> <gradient android:startColor="#00f" android:centerColor="#0f0" android:endColor="#f00"></gradient></shape>

13.

<shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="oval"> <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置描邊色 --> <stroke android:width="2dp" android:color="#f00" ></stroke></shape>

14.

<shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="oval"> <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置漸變填充色 --> <gradient android:startColor="#f00" android:centerColor="#0f0" android:endColor="#00f" android:gradientRadius="60" android:type="sweep"></gradient></shape>

15.

<shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="oval"> <size android:width="60dp" android:height="30dp"/> <!-- 設(shè)置描邊色 --> <stroke android:width="2dp" android:color="#f00" android:dashWidth="5dp" android:dashGap="5dp"></stroke></shape>

16.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="20dp" android:shape="ring" android:thickness="2dp" android:useLevel="false" > <!-- 設(shè)置固定填充色 --> <solid android:color="#f00" /> <size android:height="44dp" /></shape>

17.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="20dp" android:shape="ring" android:thickness="2dp" android:useLevel="false" > <!-- 設(shè)置漸變填充色 --> <gradient android:startColor="#00f" android:centerColor="#0f0" android:endColor="#f00"/> <size android:height="44dp" /></shape>

18.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="20dp" android:shape="ring" android:thickness="2dp" android:useLevel="false" > <!-- 設(shè)置漸變填充色 --> <gradient android:startColor="#00f" android:centerColor="#0f0" android:endColor="#f00"/> <size android:height="44dp" /> <stroke android:width="2dp" android:color="#f00" android:dashWidth="5dp" android:dashGap="5dp"/></shape>

19.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="20dp" android:shape="ring" android:thickness="2dp" android:useLevel="false" > <size android:height="44dp" /> <stroke android:width="2dp" android:color="#f00" android:dashWidth="5dp" android:dashGap="5dp"/></shape>

20.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="20dp" android:shape="ring" android:innerRadiusRatio="8" android:useLevel="false" > <!-- 設(shè)置漸變填充色 --> <gradient android:startColor="#00f" android:centerColor="#0f0" android:endColor="#f00"/> <size android:height="44dp" /></shape>

21.

<shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="line"> <stroke android:width="1dp" android:color="#f00"/> <size android:height="2dp"></size></shape>

22.

<shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="line"> <stroke android:width="1dp" android:color="#f00"/> <size android:height="10dp"></size></shape>

23.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" > <stroke android:dashGap="8px" android:dashWidth="8px" android:width="1dp" android:color="#f00" /> <size android:height="30dip" /></shape>

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對(duì)VEVB武林網(wǎng)的支持。


注:相關(guān)教程知識(shí)閱讀請移步到Android開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 广德县| 梁河县| 万源市| 修武县| 长春市| 繁昌县| 乳山市| 永顺县| 陆河县| 高州市| 临颍县| 龙井市| 监利县| 西乌| 册亨县| 周口市| 武穴市| 宁明县| 寻甸| 铜鼓县| 崇文区| 永安市| 北海市| 中牟县| 栾川县| 德安县| 湖南省| 通化县| 萝北县| 屯留县| 冀州市| 佛学| 陆河县| 通州区| 西乌珠穆沁旗| 太白县| 通道| 托克托县| 商丘市| 呼伦贝尔市| 铜梁县|