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

歡迎訪問 生活随笔!

生活随笔

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

Android

Android 使用控件自定义背景实例

發(fā)布時間:2023/12/10 Android 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

這是描邊屬性,可以定義描邊的寬度,顏色,虛實線等

  • <stroke?????????
  • ????android:width="dimension"???//描邊的寬度????
  • ????android:color="color"???//描邊的顏色????
  • ????//?以下兩個屬性設(shè)置虛線????
  • ????android:dashWidth="dimension"???//虛線的寬度,值為0時是實線????
  • ????android:dashGap="dimension"?/>??????//虛線的間隔?
  • <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" ><strokeandroid:width="10dp"android:color="#00ff00"android:dashWidth="17dp"android:dashGap="5dp" /> </shape>

    ?

    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標簽是用來字義圓角的

  • <corners????//定義圓角????
  • ????android:radius="dimension"??????//全部的圓角半徑????
  • ????android:topLeftRadius="dimension"???//左上角的圓角半徑????
  • ????android:topRightRadius="dimension"??//右上角的圓角半徑????
  • ????android:bottomLeftRadius="dimension"????//左下角的圓角半徑????
  • ????android:bottomRightRadius="dimension"?/>????//右下角的圓角半徑?
  • ?

    <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)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。