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

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

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

系統 2803 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條評論
主站蜘蛛池模板: 永兴县| 鄂尔多斯市| 普兰店市| 祥云县| 郴州市| 宿迁市| 泊头市| 华阴市| 盐山县| 濉溪县| 鹿邑县| 新和县| 阿合奇县| 沈丘县| 临清市| 渝北区| 司法| 广州市| 青川县| 定日县| 天津市| 林州市| 民权县| 兴安盟| 福安市| 竹北市| 永康市| 桑植县| 临沭县| 衡阳县| 新巴尔虎右旗| 武威市| 庆阳市| 屏南县| 呈贡县| 改则县| 漠河县| 来宾市| 济源市| 鹿邑县| 那曲县|