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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android学习笔记34——ClipDrawable资源

發(fā)布時(shí)間:2025/4/16 编程问答 91 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android学习笔记34——ClipDrawable资源 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

ClipDrawable

ClipDrawable代表從其他位圖上截取一個(gè)“圖片片段”

在XML文件中定義ClipDrawable對(duì)象使用<clip.../>元素,該元素的語法為:

以上語法格式中可指定如下三個(gè)屬性:

1.android:drawable:指定截取的源Drawable對(duì)象

2.android:clipOrientaton:指定截取方向,可設(shè)置水平或垂直截取

3.android:gravity:指定截取時(shí)的對(duì)齊方式

注:使用ClipDrawable對(duì)象是可調(diào)用setLevel(int levle)方法設(shè)置截取的區(qū)域大小,當(dāng)level為0時(shí),截取的圖片片段為空;當(dāng)level為10000時(shí),截取整張圖片。

實(shí)例如下:徐徐展開的風(fēng)景

注意:實(shí)際開發(fā)中,可采用該種方式完成進(jìn)度顯示控制。

資源文件==》drawable文件夾下 <?xml version="1.0" encoding="utf-8"?> <clip xmlns:android="http://schemas.android.com/apk/res/android"android:clipOrientation="horizontal"android:drawable="@drawable/people"android:gravity="center" ></clip>布局文件==》 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity" ><ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/myclip" /> </LinearLayout>代碼實(shí)現(xiàn)==》 package com.example.myclipdrawable;import java.util.Timer; import java.util.TimerTask; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.annotation.SuppressLint; import android.app.Activity; import android.graphics.drawable.ClipDrawable; import android.view.Menu; import android.widget.ImageView;@SuppressLint("HandlerLeak") public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ImageView img = (ImageView) this.findViewById(R.id.image);final ClipDrawable drawable = (ClipDrawable) img.getDrawable();final Handler hanler = new Handler(){@Overridepublic void handleMessage(Message msg){if (msg.what == 1){int value=drawable.getLevel() + 200;drawable.setLevel(value);}}};final Timer timer = new Timer();timer.schedule(new TimerTask(){@Overridepublic void run(){Message msg = new Message();msg.what = 1;hanler.sendMessage(msg);// 取消定時(shí)器if (drawable.getLevel() >= 10000){timer.cancel();}}}, 0, 300);}@Overridepublic boolean onCreateOptionsMenu(Menu menu){// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}

運(yùn)行效果:隨著時(shí)間的變化,圖片逐漸被截取完成

???? ??

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/YYkun/p/5848750.html

總結(jié)

以上是生活随笔為你收集整理的android学习笔记34——ClipDrawable资源的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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