日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

android中的shape资源,Android Drawable资源讲解之shape篇

發(fā)布時(shí)間:2023/12/4 Android 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android中的shape资源,Android Drawable资源讲解之shape篇 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

運(yùn)用好Android的drawable資源,在開發(fā)中就可以減少圖片的使用量,這樣既縮小了app的體積,也省去了設(shè)計(jì)圖片的時(shí)間,而且也容易適配不同的屏幕尺寸。

今天首先來講講shape資源的使用。

1. Shape的屬性介紹

shape共支持四種形狀,在根節(jié)點(diǎn)通過android:shape=””來定義

rectangle

方形

oval

橢圓形

line

線形,需要節(jié)點(diǎn)來定義其屬性

ring

環(huán)形

我們常用的應(yīng)該是rectangle和oval形狀,我們上個(gè)圖來看一下總體效果:

其中下面幾個(gè)屬性是環(huán)形時(shí)才會(huì)用到的:

android:innerRadius

尺寸。環(huán)內(nèi)部(中間的孔)的半徑,以尺寸值或尺寸資源表示。

android:innerRadiusRatio

浮點(diǎn)型。環(huán)內(nèi)部的半徑,以環(huán)寬度的比率表示。例如,如果 android:innerRadiusRatio=”5″,則內(nèi)半徑等于環(huán)寬度除以 5。此值被 android:innerRadius 覆蓋。默認(rèn)值為 9。

android:thickness

尺寸。環(huán)的厚度,以尺寸值或尺寸資源表示。

android:thicknessRatio

浮點(diǎn)型。環(huán)的厚度,表示為環(huán)寬度的比率。例如,如果 android:thicknessRatio=”2″,則厚度等于環(huán)寬度除以 2。此值被 android:innerRadius 覆蓋。默認(rèn)值為 3。

android:useLevel

布爾值。如果這用作 LevelListDrawable,則此值為“true”。這通常應(yīng)為“false”,否則形狀不會(huì)顯示。當(dāng)我們要設(shè)計(jì)一個(gè)圓形時(shí)必須設(shè)置它為false。

2.子節(jié)點(diǎn)之實(shí)色填充效果

solid節(jié)點(diǎn)可以實(shí)現(xiàn)形狀的填充效果,通過android:color屬性設(shè)置顏色值,如下示例:

XHTML

android:shape="rectangle">

1

2

3

4

5

6

android:shape="rectangle">

3.子節(jié)點(diǎn)之漸變填充效果

gradient節(jié)點(diǎn)可以實(shí)現(xiàn)漸變的填充效果,示例如下:

XHTML

android:shape="rectangle">

android:endColor="#33ddee"

android:centerColor="#eedd33"

android:angle="90"

android:centerX="0.4"

android:centerY="0.4"

android:type="linear">

1

2

3

4

5

6

7

8

9

10

11

12

android:shape="rectangle">

android:endColor="#33ddee"

android:centerColor="#eedd33"

android:angle="90"

android:centerX="0.4"

android:centerY="0.4"

android:type="linear">

4.子節(jié)點(diǎn)之實(shí)現(xiàn)邊框效果

XHTML

android:shape="rectangle">

android:endColor="#33ddee"

android:centerColor="#eedd33"

android:angle="90"

android:centerX="0.4"

android:centerY="0.4"

android:type="linear">

android:width="2dp"

android:dashGap="2dp"

android:dashWidth="2dp">

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

android:shape="rectangle">

android:endColor="#33ddee"

android:centerColor="#eedd33"

android:angle="90"

android:centerX="0.4"

android:centerY="0.4"

android:type="linear">

android:width="2dp"

android:dashGap="2dp"

android:dashWidth="2dp">

各個(gè)屬性值的解釋:

android:color

線框的顏色

android:width

線框的寬度

android:dashGap

如果畫虛線框,虛線框的間隙

android:dashWidth

如果畫虛線框,虛線框的寬度

5.子節(jié)點(diǎn)之實(shí)現(xiàn)圓角效果

為了美觀,我們?cè)诋嫲粹o時(shí)都會(huì)給按鈕背影加個(gè)圓角效果,在shape里可以通過corner節(jié)點(diǎn)來實(shí)現(xiàn)圓角效果,如下所示:

XHTML

android:shape="rectangle">

android:endColor="#33ddee"

android:centerColor="#eedd33"

android:angle="90"

android:centerX="0.4"

android:centerY="0.4"

android:type="linear">

android:width="1dp">

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

android:shape="rectangle">

android:endColor="#33ddee"

android:centerColor="#eedd33"

android:angle="90"

android:centerX="0.4"

android:centerY="0.4"

android:type="linear">

android:width="1dp">

radius用于設(shè)置圓角的半徑大小,也可以通過android:topLeftRadius,android:topRightRadius,android:bottomLeftRadius,android:bottomRightRadius分別設(shè)置四個(gè)角的圓角半徑大小,比如在實(shí)現(xiàn)tab標(biāo)簽頭部按鈕時(shí),我們可能只需要為左上和右上角設(shè)置圓角效果。比如還可以實(shí)現(xiàn)一些特殊形狀的導(dǎo)航按鈕等等。

6.padding節(jié)點(diǎn)

padding節(jié)點(diǎn)用于設(shè)置形狀相對(duì)于四邊的內(nèi)部間距,可以用于在layer-list中設(shè)置陰影的效果。

打賞

微信掃一掃,打賞作者吧~

總結(jié)

以上是生活随笔為你收集整理的android中的shape资源,Android Drawable资源讲解之shape篇的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。