Android中ClipDrawable的用法

來源:互聯網
上載者:User

今天想把drawable下的所有Drawable Resources 弄清楚,看到Clip Drawable 的時候,把以下原文檔裡的列子考到自己建的項目下

clip.xml

<?xml version="1.0" encoding="utf-8"?>

<clip xmlns:android=http://schemas.android.com/apk/res/android

android:drawable="@drawable/android"

 android:clipOrientation="horizontal"

 android:gravity="left" />

</clip>-----------------------------①

 

main.xml加入

<ImageView android:id="@+id/image" android:background="@drawable/clip" android:layout_height="wrap_content" android:layout_width="wrap_content" />

 

MainActivity加入

ImageView imageview = (ImageView) findViewById(R.id.image);

ClipDrawable drawable = (ClipDrawable) imageview.getDrawable();-------------------------②

drawable.setLevel(drawable.getLevel() + 1000);

 

當這樣做好之後,你會發現①處根本是多餘的。這個很容易發現。

其二,②處竟然報null 指標異常。

看了ClipDrawable中的方法已及clip.xml中android:drawable="@drawable/android"找到了這個方法

ClipDrawable drawable = (ClipDrawable) imageview.getBackground();

改成上述就可以運行了。

 

擦,浪費哥1個多小時,誰來負責?!擦,那來源文件裡德運行圖案不知道到底是怎麼來的,氣憤!希望看到這篇文章也用到這個的朋友別再走彎路了。

今天想把drawable下的所有Drawable Resources 弄清楚,看到Clip Drawable 的時候,把以下原文檔裡的列子考到自己建的項目下

clip.xml

<?xml version="1.0" encoding="utf-8"?>

<clip xmlns:android=http://schemas.android.com/apk/res/android

android:drawable="@drawable/android"

 android:clipOrientation="horizontal"

 android:gravity="left" />

</clip>-----------------------------①

 

main.xml加入

<ImageView android:id="@+id/image" android:background="@drawable/clip" android:layout_height="wrap_content" android:layout_width="wrap_content" />

 

MainActivity加入

ImageView imageview = (ImageView) findViewById(R.id.image);

ClipDrawable drawable = (ClipDrawable) imageview.getDrawable();-------------------------②

drawable.setLevel(drawable.getLevel() + 1000);

 

當這樣做好之後,你會發現①處根本是多餘的。這個很容易發現。

其二,②處竟然報null 指標異常。

看了ClipDrawable中的方法已及clip.xml中android:drawable="@drawable/android"找到了這個方法

ClipDrawable drawable = (ClipDrawable) imageview.getBackground();

改成上述就可以運行了。

 

擦,浪費哥1個多小時,誰來負責?!擦,那來源文件裡德運行圖案不知道到底是怎麼來的,氣憤!希望看到這篇文章也用到這個的朋友別再走彎路了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.