色偷偷偷亚洲综合网另类,亚洲欧美另类在线观看,欧美午夜激情在线,久久久精品一区

當前位置:首頁 > 嵌入式培訓 > 嵌入式學習 > 講師博文 > Android圖形圖像Drawable的使用(二)

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

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

圖 1

(1) BitmapDrawable

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

本文引用地址://www.17old.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>

上面三個TextView分別使用了不同的BitmapDrawable的tileMode,下面分別貼出這三個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>

上面三個TextView分別使用了不同的ShapeDrawable的type,下面分別貼出這三個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代碼,作為TextView的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代碼,作為TextView的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時顯示此狀態 -->

<item <>

android:drawable="@drawable/button_focused"

android:state_focused="true"/>

<!-- 沒有按下TextView且獲得焦點時顯示此狀態 -->

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

<!-- TextView默認狀態 -->

</selector>

(5) LevelListDrawable

直接貼出levellist_drawable.xml代碼,作為TextView的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"/>

<!-- 當level為0~1000時,顯示此Drawable -->

<item <>

android:drawable="@drawable/high_level"

android:maxLevel="10000"

android:minLevel="1001"/>

 <!-- 當level為1001~10000時,顯示此Drawable -->

</level-list>

(6) InsetDrawable

直接貼出inset_drawable.xml代碼,作為TextView的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);

上一篇:關于C指針的一些理解

下一篇:Android內存泄漏

熱點文章推薦
華清學員就業榜單
高薪學員經驗分享
熱點新聞推薦
前臺專線:010-82525158 企業培訓洽談專線:010-82525379 院校合作洽談專線:010-82525379 Copyright © 2004-2022 北京華清遠見科技集團有限公司 版權所有 ,京ICP備16055225號-5京公海網安備11010802025203號

回到頂部

色偷偷偷亚洲综合网另类,亚洲欧美另类在线观看,欧美午夜激情在线,久久久精品一区
主站蜘蛛池模板: 日本亚洲欧洲色α| 午夜精品国产精品大乳美女| 日韩欧美精品网站| 国产精品网址在线| 最新中文字幕亚洲| 欧美亚州一区二区三区| 精品亚洲男同gayvideo网站| 九九精品视频在线| 91亚洲国产精品| 丁香五六月婷婷久久激情| 久久久亚洲精选| 欧美大胆在线视频| 欧美亚州一区二区三区| 亚洲成人久久久| 国模吧一区二区三区| 亚洲国产另类久久精品| 精品久久中文字幕久久av| 国产成人精品在线观看| 中文字幕久久久| 国产精品亚发布| 精品久久久久久久久中文字幕| 成人a免费视频| 欧美午夜精品伦理| 亚洲欧洲午夜一线一品| 热99在线视频| 美女啪啪无遮挡免费久久网站| 91免费视频网站| 亚洲91av视频| 久久天天躁日日躁| 亚洲精品成人av| 国产精品91在线| 狠狠躁夜夜躁人人爽天天天天97 | 精品久久久91| 成人免费看黄网站| 欧美在线视频观看免费网站| 国产一区二区三区四区福利| 久久午夜a级毛片| 久久久久久久影院| 亚洲欧美自拍一区| 成人黄色免费网站在线观看| 国内免费久久久久久久久久久|