歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android開發教程:shape和selector的結合使用

Android開發教程:shape和selector的結合使用

日期:2017/3/1 10:36:26   编辑:Linux編程

shape和selector是Android UI設計中經常用到的,比如我們要自定義一個圓角Button,點擊Button有些效果的變化,就要用到shape和selector。可以這樣說,shape和selector在美化控件中的作用是至關重要的。

1.Shape

簡介

作用:XML中定義的幾何形狀

位置:res/drawable/文件的名稱.xml

使用的方法:

Java代碼中:R.drawable.文件的名稱

XML中:android:background="@drawable/文件的名稱"

屬性:

<shape> android:shape=["rectangle" | "oval" | "line" | "ring"]

其中rectagle矩形,oval橢圓,line水平直線,ring環形

<shape>中子節點的常用屬性:

<gradient> 漸變

android:startColor 起始顏色

android:endColor 結束顏色

android:angle 漸變角度,0從上到下,90表示從左到右,數值為45的整數倍默認為0;

android:type 漸變的樣式 liner線性漸變 radial環形漸變 sweep

<solid > 填充

android:color 填充的顏色

<stroke > 描邊

android:width 描邊的寬度

android:color 描邊的顏色

android:dashWidth 表示'-'橫線的寬度

android:dashGap 表示'-'橫線之間的距離

<corners > 圓角

android:radius 圓角的半徑 值越大角越圓

android:topRightRadius 右上圓角半徑

android:bottomLeftRadius 右下圓角角半徑

android:topLeftRadius 左上圓角半徑

android:bottomRightRadius 左下圓角半徑

Copyright © Linux教程網 All Rights Reserved