色yeye在线视频观看_亚洲人亚洲精品成人网站_一级毛片免费播放_91精品一区二区中文字幕_一区二区三区日本视频_成人性生交大免费看

當(dāng)前位置:首頁(yè) > 嵌入式培訓(xùn) > 嵌入式學(xué)習(xí) > 講師博文 > Android圖形圖像Drawable的使用(二)

Android圖形圖像Drawable的使用(二) 時(shí)間:2018-09-27      來(lái)源:未知

在本文中,程序統(tǒng)一使用的原圖為image.jpg,如圖 1。

圖 1

(1) BitmapDrawable

首先是MainActivity的布局文件activity_main.xml。

本文引用地址://www.einuk.cn/emb/Column/7551.html

<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"

xmlns:tools="//schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

tools:context="com.example.drawabletest.MainActivity" >

<TextView <>

android:id="@+id/text1"

android:layout_width="100dp"

android:layout_height="100dp"

android:layout_margin="2dp"

android:background="@drawable/bitmap_drawable_repeat" />

<TextView <>

android:id="@+id/text2"

android:layout_width="100dp"

android:layout_height="100dp"

android:layout_margin="2dp"

android:background="@drawable/bitmap_drawable_mirror" />

<TextView <>

android:id="@+id/text3"

android:layout_width="100dp"

android:layout_height="100dp"

android:layout_margin="2dp"

android:background="@drawable/bitmap_drawable_clamp" />

</LinearLayout>

上面三個(gè)TextView分別使用了不同的BitmapDrawable的tileMode,下面分別貼出這三個(gè)Drawable的xml文件。

bitmap_drawable_repeat.xml:

<?xml version="1.0" encoding="utf-8"?>

<bitmap xmlns:android="//schemas.android.com/apk/res/android"

android:src="@drawable/image"

android:tileMode="repeat" />

bitmap_drawable_mirror.xml:

<?xml version="1.0" encoding="utf-8"?>

<bitmap xmlns:android="//schemas.android.com/apk/res/android"

android:src="@drawable/image"

android:tileMode="mirror" />

bitmap_drawable_clamp.xml:

<?xml version="1.0" encoding="utf-8"?>

<bitmap xmlns:android="//schemas.android.com/apk/res/android"

android:src="@drawable/image"

android:tileMode="clamp" />

顯示效果如圖 2。

圖 2

(2) ShapeDrawable

首先是MainActivity的布局文件activity_main.xml。

<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"

xmlns:tools="//schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal"

tools:context="com.example.drawabletest.MainActivity" >

<TextView <>

android:id="@+id/text1"

android:layout_width="100dp"

android:layout_height="100dp"

android:layout_margin="2dp"

android:background="@drawable/shape_drawable_gradient_linear" />

<TextView <>

android:id="@+id/text2"

android:layout_width="100dp"

android:layout_height="100dp"

android:layout_margin="2dp"

android:background="@drawable/shape_drawable_gradient_radius" />

<TextView <>

android:id="@+id/text3"

android:layout_width="100dp"

android:layout_height="100dp"

android:layout_margin="2dp"

android:background="@drawable/shape_drawable_gradient_sweep" />

</LinearLayout>

上面三個(gè)TextView分別使用了不同的ShapeDrawable的type,下面分別貼出這三個(gè)Drawable的xml文件。

shape_drawable_gradient_linear.xml:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="//schemas.android.com/apk/res/android"

android:shape="rectangle" >

<gradient <>

android:angle="45"

android:centerColor="#00ff00"

android:centerX="0.5"

android:centerY="0.5"

android:endColor="#0000ff"

android:startColor="#ff0000"

android:type="linear" />

</shape>

shape_drawable_gradient_radius.xml:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="//schemas.android.com/apk/res/android"

android:shape="rectangle" >

<gradient <>

android:centerColor="#00ff00"

android:endColor="#0000ff"

android:gradientRadius="50"

android:startColor="#ff0000"

android:type="radial" />

</shape>

shape_drawable_gradient_sweep.xml:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="//schemas.android.com/apk/res/android"

android:shape="rectangle" >

<gradient <>

android:centerColor="#00ff00"

android:endColor="#0000ff"

android:gradientRadius="50"

android:startColor="#ff0000"

android:type="radial" />

</shape>

顯示效果如圖 3。

圖 3

(3) LayerDrawable

直接貼出layer_drawable.xml代碼,作為T(mén)extView的background。

<item>

<shape android:shape="rectangle" >

<solid android:color="#ff0000" />

</shape>

</item>

<item android:bottom="20dp">

<shape android:shape="rectangle" >

<solid android:color="#00ff00" />

</shape>

</item>

<item

<>

android:bottom="10dp"

android:left="10dp"

android:right="10dp">

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="//schemas.android.com/apk/res/android" >

<shape android:shape="rectangle" >

<solid android:color="#0000ff" />

</shape>

</item>

</layer-list>

顯示效果如圖 4。

圖 4

(4) StateListDrawable

直接貼出statelist_drawable.xml代碼,作為T(mén)extView的background。

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="//schemas.android.com/apk/res/android" >

<item

android:drawable="@drawable/button_pressed"

android:state_pressed="true"/>

<!-- 按下TextView時(shí)顯示此狀態(tài) -->

<item <>

android:drawable="@drawable/button_focused"

android:state_focused="true"/>

<!-- 沒(méi)有按下TextView且獲得焦點(diǎn)時(shí)顯示此狀態(tài) -->

<item android:drawable="@drawable/button_normal"/>

<!-- TextView默認(rèn)狀態(tài) -->

</selector>

(5) LevelListDrawable

直接貼出levellist_drawable.xml代碼,作為T(mén)extView的background。

<?xml version="1.0" encoding="utf-8"?>

<level-list xmlns:android="//schemas.android.com/apk/res/android" >

<item <>

android:drawable="@drawable/low_level"

android:maxLevel="1000"

android:minLevel="0"/>

<!-- 當(dāng)level為0~1000時(shí),顯示此Drawable -->

<item <>

android:drawable="@drawable/high_level"

android:maxLevel="10000"

android:minLevel="1001"/>

 <!-- 當(dāng)level為1001~10000時(shí),顯示此Drawable -->

</level-list>

(6) InsetDrawable

直接貼出inset_drawable.xml代碼,作為T(mén)extView的background。

<?xml version="1.0" encoding="utf-8"?>

<inset xmlns:android="//schemas.android.com/apk/res/android"

android:insetBottom="15dp"

android:insetLeft="15dp"

android:insetRight="15dp"

android:insetTop="15dp" >

<shape android:shape="rectangle" >

<solid android:color="#00ff00" />   

</shape>

</inset> 

(7) ClipDrawable

直接貼出clip_drawable.xml代碼,作為ImageView的background。

<?xml version="1.0" encoding="utf-8"?>

<clip xmlns:android="//schemas.android.com/apk/res/android"  

android:clipOrientation="vertical"

android:drawable="@drawable/image"

android:gravity="bottom" />

ImageView的布局為:

<ImageView

android:id="@+id/img1"

android:layout_width="100dp"

android:layout_height="100dp"

android:gravity="center"

android:src="@drawable/clip_drawable" />

MainActivity.java代碼中:

ImageView mImageView = (ImageView) findViewById(R.id.img1);

ClipDrawable clipDrawable = (ClipDrawable)mImageView.getDrawable();

clipDrawable.setLevel(5000);

上一篇:關(guān)于C指針的一些理解

下一篇:Android內(nèi)存泄漏

熱點(diǎn)文章推薦
華清學(xué)員就業(yè)榜單
高薪學(xué)員經(jīng)驗(yàn)分享
熱點(diǎn)新聞推薦
前臺(tái)專(zhuān)線:010-82525158 企業(yè)培訓(xùn)洽談專(zhuān)線:010-82525379 院校合作洽談專(zhuān)線:010-82525379 Copyright © 2004-2022 北京華清遠(yuǎn)見(jiàn)科技集團(tuán)有限公司 版權(quán)所有 ,京ICP備16055225號(hào)-5,京公海網(wǎng)安備11010802025203號(hào)

回到頂部

主站蜘蛛池模板: 五月丁香六月综合缴情在线 | 最新精品露脸国产在线 | 亚洲人色婷婷成人网站在线观看 | 亚洲A∨精品无码一区二区 亚洲精品一区二区三区精品 | 亚洲AV中文无码乱人伦在线视色 | 国产超薄丝袜足底脚交国产 | 伊人久久大香线蕉av最新 | 大又大粗又爽又黄少妇毛片 | 亚洲欧美日韩在线资源观看 | 久久精品亚洲中文字幕无码麻豆 | 亚洲国产综合在线观看不卡 | 蜜桃色欲AV久久无码精品 | 亚洲日韩亚洲另类激情文学一 | 久久人人爽av亚洲精品 | 人人人人爽 | 伊人久久大香线焦av综合影院 | 大地资源在线视频在线观看 | 国产免费高清视频在线一区二区 | 色噜噜狠狠一区二区三区果冻 | 伊人成色综合人夜夜久久 | 国产一二在线 | 久久久久久久婷婷 | 精品国产成人亚洲午夜福利 | 波多野结衣在线精品视频 | 亚洲精品色播一区二区 | 国产高清自拍视频在线观看 | 中文字幕人妻偷伦在线视频 | 国产chinese男男GAYGAY视频网站 | 未满小14洗澡无码视频网站 | 日韩一页 | 脱了美女内裤猛烈啪啪爽 | 正在播放日韩欧美 一页 | 日韩高清在线中文字带字幕 | 欧洲美女粗暴牲交视频免费 | 国产裸体裸拍免费观看 | 国产亚洲精品久久久久秋霞 | 国产精品va无码欧美二区 | 女同免费毛片在线播放 | 国产精品无码AV一区二区三区 | 伊人色综合久久天天人手人婷 | 新婚之夜玩弄人妻系列 |