久久96国产精品久久久-久久发布国产伦子伦精品-久久精品国产精品青草-久久天天躁夜夜躁狠狠85麻豆

技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機(jī)純凈版,64位旗艦版,綠色軟件,免費(fèi)軟件下載基地!

當(dāng)前位置:主頁(yè) > 教程 > 服務(wù)器類 >

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

來(lái)源:技術(shù)員聯(lián)盟┆發(fā)布時(shí)間:2017-09-02 18:04┆點(diǎn)擊:

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

二,shape初識(shí)

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

ectangle:

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

oval:

ovel,橢圓,用它可以畫(huà)橢圓,圓

line:

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

ring:

環(huán)形

下面我們來(lái)用上面說(shuō)道的各種形狀畫(huà)圖形,打造各種簡(jiǎn)單的形狀

三,shape的使用

下面看看用shape畫(huà)的一些簡(jiǎn)單的圖形,之后我會(huì)按照?qǐng)D形說(shuō)一下shape的各種屬性以及一些要注意的問(wèn)題:

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

1.實(shí)心長(zhǎng)方形

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

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

<shape xmlns: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.長(zhǎng)方形外框

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

4.虛線長(zhǎng)方形外框

<shape xmlns: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="" > <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í)心長(zhǎng)方體切圓角

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

7.

<shape xmlns: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="" > <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="" > <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="" > <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.