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

