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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

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

發布時間:2023/12/4 Android 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android中的shape资源,Android Drawable资源讲解之shape篇 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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

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

1. Shape的屬性介紹

shape共支持四種形狀,在根節點通過android:shape=””來定義

rectangle

方形

oval

橢圓形

line

線形,需要節點來定義其屬性

ring

環形

我們常用的應該是rectangle和oval形狀,我們上個圖來看一下總體效果:

其中下面幾個屬性是環形時才會用到的:

android:innerRadius

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

android:innerRadiusRatio

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

android:thickness

尺寸。環的厚度,以尺寸值或尺寸資源表示。

android:thicknessRatio

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

android:useLevel

布爾值。如果這用作 LevelListDrawable,則此值為“true”。這通常應為“false”,否則形狀不會顯示。當我們要設計一個圓形時必須設置它為false。

2.子節點之實色填充效果

solid節點可以實現形狀的填充效果,通過android:color屬性設置顏色值,如下示例:

XHTML

android:shape="rectangle">

1

2

3

4

5

6

android:shape="rectangle">

3.子節點之漸變填充效果

gradient節點可以實現漸變的填充效果,示例如下:

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.子節點之實現邊框效果

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">

各個屬性值的解釋:

android:color

線框的顏色

android:width

線框的寬度

android:dashGap

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

android:dashWidth

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

5.子節點之實現圓角效果

為了美觀,我們在畫按鈕時都會給按鈕背影加個圓角效果,在shape里可以通過corner節點來實現圓角效果,如下所示:

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用于設置圓角的半徑大小,也可以通過android:topLeftRadius,android:topRightRadius,android:bottomLeftRadius,android:bottomRightRadius分別設置四個角的圓角半徑大小,比如在實現tab標簽頭部按鈕時,我們可能只需要為左上和右上角設置圓角效果。比如還可以實現一些特殊形狀的導航按鈕等等。

6.padding節點

padding節點用于設置形狀相對于四邊的內部間距,可以用于在layer-list中設置陰影的效果。

打賞

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

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。