Android 使用控件自定义背景实例
生活随笔
收集整理的這篇文章主要介紹了
Android 使用控件自定义背景实例
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
實例1
<?xml version="1.0" encoding="UTF-8"?> <!-- 底部圓角 白色背景 灰色邊框 長方體 --> <layer-list xmlns:tools="http://schemas.android.com/tools"xmlns:android="http://schemas.android.com/apk/res/android"tools:ignore="MissingDefaultResource"><item><shape><solid android:color="@color/blue" /><corners android:topLeftRadius="0dp" android:topRightRadius="10dp"android:bottomRightRadius="10dp" android:bottomLeftRadius="0dp" /><stroke android:width="0dp" android:color="@color/blue" /></shape></item> <!-- 四個外邊的線的寬度--><item android:top="1dp" android:bottom="1dp" android:left="1dp" android:right="1dp"><shape><solid android:color="@color/white" /><corners android:topLeftRadius="0dp" android:topRightRadius="10dp"android:bottomRightRadius="10dp" android:bottomLeftRadius="0dp" /><stroke android:width="0dp" android:color="@color/white" /></shape></item> </layer-list>實例2
<?xml version="1.0" encoding="UTF-8"?> <!-- 底部圓角 白色背景 灰色邊框 長方體 --> <layer-list xmlns:tools="http://schemas.android.com/tools"xmlns:android="http://schemas.android.com/apk/res/android"tools:ignore="MissingDefaultResource"><item><shape><solid android:color="@color/white" /><corners android:topLeftRadius="10dp" android:topRightRadius="0dp"android:bottomRightRadius="0dp" android:bottomLeftRadius="10dp" /><stroke android:width="0dp" android:color="@color/white" /></shape></item><item android:top="0dp" android:bottom="0dp" android:left="0dp" android:right="0dp"><shape><solid android:color="@color/blue" /><corners android:topLeftRadius="10dp" android:topRightRadius="0dp"android:bottomRightRadius="0dp" android:bottomLeftRadius="10dp" /><stroke android:width="0dp" android:color="@color/blue" /></shape></item> </layer-list>?
?
shape可設(shè)置view的形狀背景背影等
1、stroke
這是描邊屬性,可以定義描邊的寬度,顏色,虛實線等
?
2、gradient
gradient用以定義漸變色,可以定義兩色漸變和三色漸變,及漸變樣式,它的屬性有下面幾個:
?android:type=["linear"?|?"radial"?|?"sweep"]????//共有3中漸變類型,線性漸變(默認)/放射漸變/掃描式漸變
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" ><gradientandroid:type="sweep"android:startColor="#ff0000"android:centerColor="#00ff00"android:endColor="#0000ff"/> </shape>?
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" ><gradientandroid:type="linear"android:startColor="#ff0000"android:centerColor="#00ff00"android:endColor="#0000ff"/> </shape>?要加上android:gradientRadius屬性(漸變半徑)
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" ><gradientandroid:type="radial"android:startColor="#ff0000"android:centerColor="#00ff00"android:endColor="#0000ff"android:gradientRadius="100"/> </shape>3、solid
solid用以指定內(nèi)部填充色
只有一個屬性:
<solid android:color="@color/log_iconbgc" />4、Corners
Corners標簽是用來字義圓角的
?
<cornersandroid:topLeftRadius="5dp"android:topRightRadius="6dp"android:bottomLeftRadius="8dp"android:bottomRightRadius="1dp"/>?
5、shape
oval?橢圓
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><solid android:color="#ff00ff"/> </shape>ring(環(huán)形)
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="ring"android:innerRadius="20dp"android:thickness="50dp"android:useLevel="false"><solid android:color="#ff00ff"/></shape> 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的Android 使用控件自定义背景实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 当今互联网架构图
- 下一篇: Android 人脸照片对比,人脸对比