Android中drawable使用Shape資源
本文實(shí)例為大家分享了drawable使用Shape資源的具體內(nèi)容,供大家參考,具體內(nèi)容如下
1.畫(huà)一條水平方向的虛線
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" > <stroke android:dashGap="3dp" android:dashWidth="6dp" android:width="1dp" android:color="#FF8C69" /> </shape>
Android:width=”1dp” 為線條的高度
android:dashGap=”3dp” 表示虛線間空隙的寬度,0表示一條實(shí)線;
android:dashWidth=”6dp” 表示每個(gè)虛線的寬度。
注意:在版本4.0以上,需要在控件中設(shè)置android:layerType=”software”,否則虛線無(wú)效,顯示為實(shí)線。
2.畫(huà)一條垂直方向的虛線
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="90" android:toDegrees="90" android:drawable="@drawable/line" > </rotate>
或者使用下面的方法
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="90" android:toDegrees="90" > <shape android:shape="line" > <stroke android:dashGap="3px" android:dashWidth="6px" android:width="1dp" android:color="#FF8C69" /> </shape> </rotate>
3.畫(huà)一個(gè)實(shí)心圓
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <solid android:color="#FF8C69" /> </shape>
4.畫(huà)一個(gè)圓環(huán)
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="15dp" android:shape="ring" android:thickness="10dp" android:useLevel="false" > <solid android:color="#FF8C69" /> <stroke android:width="1dp" android:color="#FF8C69" /> </shape>
android:innerRadius=”15dp” 設(shè)置尺寸,內(nèi)環(huán)的半徑
android:thickness=”10dp” 設(shè)置尺寸,環(huán)的厚度
android:useLevel=”false” boolean值,如果當(dāng)做是LevelListDrawable使用時(shí)值為true,否則為false.
android:innerRadiusRatio=”9” 浮點(diǎn)型,以環(huán)的寬度比率來(lái)表示內(nèi)環(huán)的半徑,表示內(nèi)環(huán)半徑等于環(huán)的寬度除以5,這個(gè)值是可以被覆蓋的,默認(rèn)為9.
android:thicknessRatio=”2” 浮點(diǎn)型,以環(huán)的寬度比率來(lái)表示環(huán)的厚度, 表示環(huán)的厚度就等于環(huán)的寬度除以2。這個(gè)值是可以被android:thickness覆蓋的,默認(rèn)值是3.
5.畫(huà)一個(gè)矩形
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="30dp" /> <solid android:color="#FF8C69" /> <stroke android:width="1dp" android:color="#FF8C69" /> </shape>
總結(jié)
<?xml version="1.0" encoding="utf-8"?> <!-- shape drawable xml文件中定義的一個(gè)幾何圖形,定義在res/drawable/目錄下,文件名filename稱(chēng)為訪問(wèn)的資源ID 在代碼中通過(guò)R.drawable.filename進(jìn)行訪問(wèn),在xml文件中通過(guò)@[package:]drawable/filename進(jìn)行訪問(wèn)。 --> <!-- android:shape=["rectangle" | "oval" | "line" | "ring"] shape的形狀,默認(rèn)為矩形,可以設(shè)置為矩形(rectangle)、橢圓形(oval)、線性形狀(line)、環(huán)形(ring)下面的屬性只有在android:shape="ring時(shí)可用: android:innerRadius 尺寸,內(nèi)環(huán)的半徑。 android:innerRadiusRatio 浮點(diǎn)型,以環(huán)的寬度比率來(lái)表示內(nèi)環(huán)的半徑,例如,如果android:innerRadiusRatio,表示內(nèi)環(huán)半徑等于環(huán)的寬度除以5,這個(gè)值是可以被覆蓋的,默認(rèn)為9. android:thickness 尺寸,環(huán)的厚度 android:thicknessRatio 浮點(diǎn)型,以環(huán)的寬度比率來(lái)表示環(huán)的厚度,例如,如果android:thicknessRatio="2", 那么環(huán)的厚度就等于環(huán)的寬度除以2。這個(gè)值是可以被android:thickness覆蓋的,默認(rèn)值是3. android:useLevel boolean值,如果當(dāng)做是LevelListDrawable使用時(shí)值為true,否則為false. --> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- 圓角 android:radius 整型半徑 android:topLeftRadius 整型左上角半徑 android:topRightRadius 整型右上角半徑 android:bottomLeftRadius 整型左下角半徑 android:bottomRightRadius 整型右下角半徑 --> <corners android:bottomLeftRadius="20dp" android:bottomRightRadius="25dp" android:radius="8dp" android:topLeftRadius="5dp" android:topRightRadius="15dp" /> <!-- 漸變色 android:startColor 顏色值 起始顏色 android:endColor 顏色值結(jié)束顏色 android:centerColor 整型漸變中間顏色,即開(kāi)始顏色與結(jié)束顏色之間的顏色 android:angle 整型漸變角度(PS:當(dāng)angle=0時(shí),漸變色是從左向右。 然后逆時(shí)針?lè)较蜣D(zhuǎn),當(dāng)angle=90時(shí)為從下往上。angle必須為45的整數(shù)倍) android:type ["linear" | "radial" | "sweep"] 漸變類(lèi)型(取值:linear、radial、sweep) linear 線性漸變,這是默認(rèn)設(shè)置 radial 放射性漸變,以開(kāi)始色為中心。 sweep 掃描線式的漸變。 android:useLevel ["true" | "false"]如果要使用LevelListDrawable對(duì)象,就要設(shè)置為true。設(shè)置為true無(wú)漸變。false有漸變色 android:gradientRadius 整型漸變色半徑.當(dāng) android:type="radial" 時(shí)才使用。單獨(dú)使用 android:type="radial"會(huì)報(bào)錯(cuò)。 android:centerX 整型漸變中心X點(diǎn)坐標(biāo)的相對(duì)位置 android:centerY 整型漸變中心Y點(diǎn)坐標(biāo)的相對(duì)位置 --> <gradient android:angle="45" android:endColor="#80FF00FF" android:startColor="#FFFF0000" /> <!-- 內(nèi)邊距,即內(nèi)容與邊的距離 android:left 整型左內(nèi)邊距 android:top 整型上內(nèi)邊距 android:right 整型右內(nèi)邊距 android:bottom 整型下內(nèi)邊距 --> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> <!-- size 大小 android:width 整型寬度 android:height 整型高度 --> <size android:width="600dp" /> <!-- 內(nèi)部填充 android:color 顏色值填充顏色 --> <solid android:color="#ffff9d77" /> <!-- 描邊 android:width 整型描邊的寬度 android:color 顏色值描邊的顏色 android:dashWidth 整型表示描邊的樣式是虛線的寬度, 值為0時(shí),表示為實(shí)線。值大于0則為虛線。 android:dashGap 整型表示描邊為虛線時(shí),虛線之間的間隔 即“ - - - - ” --> <stroke android:width="2dp" android:color="#dcdcdc" /> </shape>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- android中圖形圖像處理之drawable用法分析
- 詳解Android中Drawable方法
- 關(guān)于Android中drawable必知的一些規(guī)則
- Android自定義Drawable實(shí)現(xiàn)圓角效果
- Android Drawable及其相關(guān)類(lèi)的使用
- Android開(kāi)發(fā)基于Drawable實(shí)現(xiàn)圓角矩形的方法
- Android自定義Drawable實(shí)現(xiàn)圓形和圓角
- Android Drawable和Bitmap的轉(zhuǎn)換實(shí)例詳解
- Android開(kāi)發(fā)使用Drawable繪制圓角與圓形圖案功能示例
- Android自定義Drawable之在Drawable中部指定透明區(qū)域方法示例
相關(guān)文章
Android?Jetpack?Compose開(kāi)發(fā)實(shí)用小技巧
這篇文章主要為大家介紹了Android?Jetpack?Compose開(kāi)發(fā)中的一些實(shí)用小技巧示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11Android sqlite cursor的遍歷實(shí)例詳解
在本篇內(nèi)容里小編給大家整理的是一篇關(guān)于Android sqlite cursor的遍歷的相關(guān)實(shí)例及知識(shí)點(diǎn),需要的朋友們可以學(xué)習(xí)下。2021-06-06詳解如何在Android中實(shí)現(xiàn)懸浮Activity
本篇文章主要介紹詳解如何在Android中實(shí)現(xiàn)懸浮Activity,通過(guò)修改Activity的實(shí)現(xiàn)來(lái)適配平板設(shè)備,已達(dá)到代碼的最大利用率。有興趣的可以了解一下。2017-01-01Android音頻錄制MediaRecorder之簡(jiǎn)易的錄音軟件實(shí)現(xiàn)代碼
這篇文章主要介紹了Android音頻錄制MediaRecorder之簡(jiǎn)易的錄音軟件實(shí)現(xiàn)代碼,有需要的朋友可以參考一下2014-01-01Android利用Service開(kāi)發(fā)簡(jiǎn)單的音樂(lè)播放功能
這篇文章主要介紹了Android利用Service開(kāi)發(fā)簡(jiǎn)單的音樂(lè)播放功能,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-04-04Android:Field can be converted to a local varible.的解決辦法
這篇文章主要介紹了Android:Field can be converted to a local varible.的解決辦法的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家遇到這樣的問(wèn)題輕松解決,需要的朋友可以參考下2017-10-10Android?自定義view中根據(jù)狀態(tài)修改drawable圖片
這篇文章主要介紹了Android?自定義view中根據(jù)狀態(tài)修改drawable圖片的相關(guān)資料,需要的朋友可以參考下2023-07-07