最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開(kāi)發(fā)教程之shape和selector的結(jié)合使用

 更新時(shí)間:2016年01月23日 20:10:41   作者:lingdududu  
shape和selector是Android UI設(shè)計(jì)中經(jīng)常用到的,比如我們要自定義一個(gè)圓角Button,點(diǎn)擊Button有些效果的變化,就要用到shape和selector,接下來(lái)通過(guò)本文給大家介紹Android開(kāi)發(fā)教程之shape和selector的結(jié)合使用,感興趣的朋友一起學(xué)習(xí)吧

shape和selector是Android UI設(shè)計(jì)中經(jīng)常用到的,比如我們要自定義一個(gè)圓角Button,點(diǎn)擊Button有些效果的變化,就要用到shape和selector。可以這樣說(shuō),shape和selector在美化控件中的作用是至關(guān)重要的。

1.Shape

簡(jiǎn)介

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

位置:res/drawable/文件的名稱(chēng).xml

使用的方法:

Java代碼中:R.drawable.文件的名稱(chēng)

XML中:android:background="@drawable/文件的名稱(chēng)"

屬性:

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

其中rectagle矩形,oval橢圓,line水平直線(xiàn),ring環(huán)形

<shape>中子節(jié)點(diǎn)的常用屬性:

<gradient> 漸變

android:startColor 起始顏色
android:endColor 結(jié)束顏色
android:angle 漸變角度,0從上到下,90表示從左到右,數(shù)值為45的整數(shù)倍默認(rèn)為0;
android:type 漸變的樣式 liner線(xiàn)性漸變 radial環(huán)形漸變 sweep
<solid > 填充
android:color 填充的顏色
<stroke > 描邊
android:width 描邊的寬度
android:color 描邊的顏色
android:dashWidth 表示'-'橫線(xiàn)的寬度
android:dashGap 表示'-'橫線(xiàn)之間的距離
<corners > 圓角
android:radius 圓角的半徑 值越大角越圓
android:topRightRadius 右上圓角半徑

android:bottomLeftRadius 右下圓角角半徑
android:topLeftRadius 左上圓角半徑
android:bottomRightRadius 左下圓角半徑

2.Selector

簡(jiǎn)介

位置:res/drawable/文件的名稱(chēng).xml

使用的方法:

Java代碼中:R.drawable.文件的名稱(chēng)

XML中:android:background="@drawable/文件的名稱(chēng)"

<?xml version="1.0" encoding="utf-8" ?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<!-- 默認(rèn)時(shí)的背景圖片--> 
<item android:drawable="@drawable/pic1" /> 
<!-- 沒(méi)有焦點(diǎn)時(shí)的背景圖片 --> 
<item 
android:state_window_focused="false" 
android:drawable="@drawable/pic_blue" 
/> 
<!-- 非觸摸模式下獲得焦點(diǎn)并單擊時(shí)的背景圖片 --> 
<item 
android:state_focused="true" 
android:state_pressed="true" 
android:drawable= "@drawable/pic_red" 
/> 
<!-- 觸摸模式下單擊時(shí)的背景圖片--> 
<item 
android:state_focused="false" 
android:state_pressed="true" 
android:drawable="@drawable/pic_pink" 
/> 
<!--選中時(shí)的圖片背景--> 
<item 
android:state_selected="true" 
android:drawable="@drawable/pic_orange" 
/> 
<!--獲得焦點(diǎn)時(shí)的圖片背景--> 
<item 
android:state_focused="true" 
android:drawable="@drawable/pic_green" 
/> 
</selector> 

第一個(gè)例子:圓角的Button

http://liangruijun.blog.51cto.com/3061169/630051

第二個(gè)例子:shape+selector綜合使用的例子 漂亮的ListView

先看看這個(gè)例子的結(jié)構(gòu):

selector.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_selected="true"> 
<shape> 
<gradient android:angle="270" android:endColor="#99BD4C" 
android:startColor="#A5D245" /> 
<size android:height="60dp" android:width="320dp" /> 
<corners android:radius="8dp" /> 
</shape> 
</item> 
<item android:state_pressed="true"> 
<shape> 
<gradient android:angle="270" android:endColor="#99BD4C" 
android:startColor="#A5D245"/> 
<size android:height="60dp" android:width="320dp" /> 
<corners android:radius="8dp" /> 
</shape> 
</item> 
<item> 
<shape> 
<gradient android:angle="270" android:endColor="#A8C3B0" 
android:startColor="#C6CFCE" /> 
<size android:height="60dp" android:width="320dp" /> 
<corners android:radius="8dp" /> 
</shape> 
</item> 
</selector> 

list_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="@drawable/selector" 
> 
<ImageView 
android:id="@+id/img" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center_vertical" 
android:layout_marginLeft="20dp" 
/> 
<TextView 
android:text="data" 
android:id="@+id/title" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:gravity="center_vertical" 
android:layout_marginLeft="20dp" 
android:layout_marginTop="20dp" 
android:textSize="14sp" 
android:textStyle="bold" 
android:textColor="@color/black" 
> 
</TextView> 
</LinearLayout>

main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="#253853" 
> 
<ListView 
android:id="@+id/list" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:cacheColorHint="#00000000" 
android:divider="#2A4562" 
android:dividerHeight="3px" 
android:listSelector="#264365" 
android:drawSelectorOnTop="false" 
> 
</ListView> 
</LinearLayout> 

colors.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<color name="white">#FFFFFFFF</color> 
<color name="transparency">#00000000</color> 
<color name="title_bg">#1C86EE</color> 
<color name="end_color">#A0cfef83</color> 
<color name="black">#464646</color> 
</resources> 

MainActivity.xml

package com.lingdududu.customlist; 
import java.util.ArrayList; 
import java.util.HashMap; 
import xb.customlist.R; 
import android.R.array; 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
import android.widget.SimpleAdapter; 
public class MainActivity extends Activity { 
ListView list; 
String data[] = new String[]{ 
"China","UK","USA","Japan","German","Canada","ET","Narotu" 
}; 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
list =(ListView) findViewById(R.id.list); 
SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.list_item, 
new String[]{"title","img"}, new int[]{R.id.title,R.id.img}); 
list.setAdapter(adapter); 
} 
private ArrayList<HashMap<String, Object>> getData() { 
ArrayList<HashMap<String, Object>> dlist = new ArrayList<HashMap<String,Object>>(); 
for(int i =0;i<data.length;i++){ 
HashMap<String, Object>map = new HashMap<String, Object>(); 
map.put("title", data[i]); 
map.put("img", R.drawable.item_left2); 
dlist.add(map); 
} 
return dlist; 
} 
}

效果圖:

以上所述是小編給大家分享的Android開(kāi)發(fā)教程之shape和selector的結(jié)合使用的相關(guān)內(nèi)容,希望對(duì)大家有所幫助。

相關(guān)文章

  • Android添加聯(lián)系人到通訊錄的方法

    Android添加聯(lián)系人到通訊錄的方法

    本周項(xiàng)目中遇到了需要添加聯(lián)系人或者添加到已有聯(lián)系人的需求,聯(lián)系人中需要保存的字段有很多,之前不太熟悉,在這里總結(jié)一下。
    2021-05-05
  • Android中Matrix用法實(shí)例分析

    Android中Matrix用法實(shí)例分析

    這篇文章主要介紹了Android中Matrix用法,以實(shí)例形式分析了Matrix矩陣運(yùn)算的常用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • Android手機(jī)端小米推送Demo解析和實(shí)現(xiàn)方法

    Android手機(jī)端小米推送Demo解析和實(shí)現(xiàn)方法

    本篇文章主要是介紹了Android端小米推送Demo解析和實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2016-10-10
  • Android編程實(shí)現(xiàn)簡(jiǎn)單流量管理功能實(shí)例

    Android編程實(shí)現(xiàn)簡(jiǎn)單流量管理功能實(shí)例

    這篇文章主要介紹了Android編程實(shí)現(xiàn)簡(jiǎn)單流量管理功能的方法,結(jié)合實(shí)例形式分析了Android實(shí)現(xiàn)流量監(jiān)控所涉及的功能模塊與布局技巧,需要的朋友可以參考下
    2016-02-02
  • 最近較流行的效果 Android自定義View實(shí)現(xiàn)傾斜列表/圖片

    最近較流行的效果 Android自定義View實(shí)現(xiàn)傾斜列表/圖片

    最近較流行的效果,這篇文章主要介紹了Android自定義View實(shí)現(xiàn)傾斜列表/圖片的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • Android使用SoundPool播放音效

    Android使用SoundPool播放音效

    這篇文章主要為大家詳細(xì)介紹了Android使用SoundPool播放音效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • Android高仿IOS 滾輪選擇控件

    Android高仿IOS 滾輪選擇控件

    這篇文章主要為大家詳細(xì)介紹了Android 高仿IOS滾輪選擇控件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android實(shí)現(xiàn)熱門(mén)標(biāo)簽的流式布局

    Android實(shí)現(xiàn)熱門(mén)標(biāo)簽的流式布局

    這篇文章主要介紹了Android實(shí)現(xiàn)熱門(mén)標(biāo)簽的流式布局的詳細(xì)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-12-12
  • Android編程中黑名單的實(shí)現(xiàn)方法

    Android編程中黑名單的實(shí)現(xiàn)方法

    這篇文章主要介紹了Android編程中黑名單的實(shí)現(xiàn)方法,結(jié)合實(shí)例形式詳細(xì)分析了Android通過(guò)對(duì)比通信錄及自動(dòng)掛斷電話(huà)等技巧實(shí)現(xiàn)黑名單功能的功能,需要的朋友可以參考下
    2016-02-02
  • 詳解四種主要的Android依賴(lài)管理方式

    詳解四種主要的Android依賴(lài)管理方式

    Android應(yīng)用開(kāi)發(fā)涉及大量的依賴(lài)庫(kù)和第三方組件,因此有效地管理這些依賴(lài)關(guān)系至關(guān)重要,本文將介紹四種主要的Android依賴(lài)管理方式,分析它們的優(yōu)點(diǎn)、缺點(diǎn)以及最佳實(shí)踐,需要的朋友可以參考下
    2023-09-09

最新評(píng)論

卓尼县| 繁峙县| 阿拉尔市| 安岳县| 淮北市| 海城市| 额济纳旗| 庆元县| 芒康县| 定西市| 鄯善县| 昌乐县| 曲沃县| 南涧| 太仓市| 井陉县| 普定县| 临泉县| 顺平县| 香格里拉县| 咸阳市| 象州县| 霍林郭勒市| 通州区| 韶山市| 通州市| 夹江县| 肇庆市| 磐安县| 留坝县| 栾川县| 万全县| 彭山县| 扬州市| 奉节县| 泌阳县| 肃宁县| 永修县| 乐至县| 金湖县| 五莲县|