概述
前面分別介紹了Rectangle矩形胞皱、oval橢圓拱绑,下面介紹一下ring環(huán)综芥、line線。
作為一個(gè)程序員猎拨,要是覺(jué)得沒(méi)事做,那是很可怕的事情屠阻,放眼一瞅红省,編碼的世界太龐大了,還有很多需要學(xué)習(xí)的地方国觉。一個(gè)行之有效的適合自己的學(xué)習(xí)方式是很有必要的吧恃,在這慢慢的編碼路程中,且行且學(xué)習(xí)吧麻诀。痕寓。傲醉。
ring環(huán)、line線效果
image
image
ring代碼實(shí)現(xiàn)
特殊屬性:shape根節(jié)點(diǎn)有些屬性呻率,只適用于ring類(lèi)型硬毕,如:
- android:innerRadius 內(nèi)環(huán)的半徑
- android:innerRadiusRatio 浮點(diǎn)型,以環(huán)的寬度比率來(lái)表示內(nèi)環(huán)的半徑礼仗,默認(rèn)為3吐咳,表示內(nèi)環(huán)半徑為環(huán)的寬度除以3,該值會(huì)被android:innerRadius覆蓋
- android:thickness 環(huán)的厚度
- android:thicknessRatio 浮點(diǎn)型元践,以環(huán)的寬度比率來(lái)表示環(huán)的厚度韭脊,默認(rèn)為9,表示環(huán)的厚度為環(huán)的寬度除以9单旁,該值會(huì)被android:thickness覆蓋
- android:useLevel 一般為false沪羔,否則可能環(huán)形無(wú)法顯示,只有作為L(zhǎng)evelListDrawable使用時(shí)才設(shè)為true
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:background="@drawable/text_shape13"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginTop="20dp"
android:background="@drawable/text_shape14"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/text_shape15" />
<TextView
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/text_shape16" />
line代碼實(shí)現(xiàn)
line主要用于畫(huà)分割線象浑,是通過(guò)stroke和size特性組合來(lái)實(shí)現(xiàn)的
<View
android:layout_width="200dp"
android:layout_height="10dp"
android:layout_marginTop="20dp"
android:background="@drawable/text_shape11"/>
<View
android:layout_width="200dp"
android:layout_height="10dp"
android:layout_marginTop="20dp"
android:background="@drawable/text_shape12"/>
shape背景
- text_shape11
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1dp"
android:color="#ff0000"/>
<size
android:height="4dp"/>
</shape>
- text_shape12
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<solid
android:color="#990000ff"/>
<stroke
android:width="1dp"
android:color="#00ff00"
android:dashWidth="4dp"
android:dashGap="4dp"/>
</shape>
- text_shape13
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="3"
android:thicknessRatio="8"
android:useLevel="false">
<solid
android:color="#990000ff"/>
<size
android:width="60dp"
android:height="60dp"/>
</shape>
- text_shape14
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="4"
android:thicknessRatio="9"
android:useLevel="false">
<solid
android:color="#990000ff"/>
<size
android:width="60dp"
android:height="60dp"/>
<gradient
android:startColor="#ff0000"
android:endColor="#00000000"
android:type="sweep"/>
</shape>
- text_shape15
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="3"
android:thicknessRatio="8"
android:useLevel="false">
<stroke
android:width="1dp"
android:color="@color/colorPrimary" />
<size
android:width="40dp"
android:height="40dp"/>
</shape>
- text_shape16
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="4"
android:thicknessRatio="9"
android:useLevel="false">
<stroke
android:width="1dp"
android:color="@color/colorPrimary" />
<size
android:width="40dp"
android:height="40dp"/>
<gradient
android:startColor="#ff0000"
android:endColor="#00000000"
android:type="sweep"/>
</shape>
總結(jié)
line劃線時(shí)注意一下幾點(diǎn):
- 只能畫(huà)水平線任内,畫(huà)不了豎線;
- 線的高度是通過(guò)stroke的android:width屬性設(shè)置的融柬;
- size的android:height屬性定義的是整個(gè)形狀區(qū)域的高度死嗦;
- size的height必須大于stroke的width,否則粒氧,線無(wú)法顯示越除;
- 線在整個(gè)形狀區(qū)域中是居中顯示的;
- 線左右兩邊會(huì)留有空白間距外盯,線越粗摘盆,空白越大;
- 引用虛線的view需要添加屬性android:layerType饱苟,值設(shè)為"software"孩擂,否則顯示不了虛線。