,截取的方向由clipOrientation控制下面以一個慢慢展開的圖片為例先定義一個ClipDrawable資源文件my_clip.xml

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

初學Android,使用Drawable資源之使用ClipDrawab

系統 2772 0

ClipDrawable代表從其它位圖上截取一個"圖片片段",XML中的根元素為<clip.../>,截取的方向由clipOrientation控制

下面以一個慢慢展開的圖片為例

先定義一個ClipDrawable資源文件my_clip.xml

?

    <?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android" 
    android:drawable="@drawable/fengjing"
    android:clipOrientation="horizontal"
    android:gravity="center">
</clip>
  

接下來在主界面main.xml中的imageview中引用它

?

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <!-- 這里imageView的src定義為clipdrawable資源 -->
    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/my_clip" />
</LinearLayout>
  

主界面代碼

?

    package WangLi.Resouce.ClipDrawableTest;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.graphics.drawable.ClipDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;

public class ClipDrawableTest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ImageView imageview = (ImageView)findViewById(R.id.image);
        //獲取圖片所顯示的ClipDrawble對象
        final ClipDrawable drawable = (ClipDrawable)imageview.getDrawable();
        final Handler handler = new Handler()
        {
        	public void handleMessage(Message msg)
        	{
        		if(msg.what == 0x1233)
        		{
        			//修改ClipDrawable的level值
        			drawable.setLevel(drawable.getLevel() +200);
        		}
        	}
        };
        final Timer timer = new Timer();
        timer.schedule(new TimerTask()
        {
        	public void run()
        	{
        		Message msg = new Message();
        		msg.what = 0x1233;
        		//發送消息,通知應用修改ClipDrawable對象的level值
        		handler.sendMessage(msg);
        		//取消定時器
        		if(drawable.getLevel() >= 10000)
        		{
        			timer.cancel();
        		}
        	}
        },0,300);
    }
}
  

運行效果如下

剛開始圖片從中間往兩邊展開

初學Android,使用Drawable資源之使用ClipDrawable資源(十六)

最后展開完整的圖片

初學Android,使用Drawable資源之使用ClipDrawable資源(十六)

利用ClipDrawable,還可以做圖片進度條

初學Android,使用Drawable資源之使用ClipDrawable資源(十六)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 建阳市| 阳城县| 古丈县| 婺源县| 聊城市| 台江县| 台山市| 仁布县| 手机| 依安县| 抚松县| 渭南市| 维西| 田林县| 房产| 吉安县| 安西县| 桐城市| 崇义县| 石渠县| 雅安市| 昭觉县| 云龙县| 敦煌市| 察隅县| 石渠县| 新野县| 九江市| 利辛县| 锡林郭勒盟| 红安县| 寿宁县| 通化市| 文山县| 唐河县| 区。| 桃江县| 准格尔旗| 扶绥县| 巴楚县| 即墨市|