Android Drawable 系列——ClipDrawable

來源:互聯網
上載者:User

ClipDrawable 是一個挺好看的一個圖片Drawable,操作起來也算比較簡單。下面先把代碼貼上來,通過例子進行說明。

main.xml檔案的內容:

<?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 android:id="@+id/image"android:layout_width="fill_parent"android:layout_height="wrap_content"android:src="@drawable/my_clip"/></LinearLayout>

這裡面重點是android:sec="@drawable/my_clip",調用了這個設定檔。這個設定檔的內容是:

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

上面定義了三個屬性。屬性一是drawable的圖片內容。第二個屬性是展開的方向,第三個屬性大家都經常用,不闡述。

這樣,一個clipDrawable的設定檔都已經搞定了。調用一個clip設定檔,展示效果。比較簡單。也很容易給項目添加一點感官上面的好處。

下面是Activity的代碼:

package cn.jason.drawable;import java.util.Timer;import java.util.TimerTask;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.widget.ImageView;public class ClipDrawable 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);                final android.graphics.drawable.ClipDrawable  drawable = (android.graphics.drawable.ClipDrawable) imageView.getDrawable();        final Handler handler = new Handler(){        @Override        public void handleMessage(Message msg) {        if (msg.what == 0x1233) {                drawable.setLevel(drawable.getLevel() + 200);                                }        }        };                final Timer timer = new Timer();        timer.schedule(new TimerTask() {@Overridepublic void run() {Message msg = new Message();msg.what= 0x1233;handler.sendMessage(msg);if (drawable.getLevel() >=10000) {                timer.cancel();                }}}, 0,300);    }                            }

上面的代碼定義了一個Handler,如果接收的是本程式的訊息,則進行操作。特別注意。定義ClipDrawable的用法是把Drawable進行轉換的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.