Android用程式碼完成色彩坡形處理

來源:互聯網
上載者:User

     android完成色彩坡形是可以靠代碼實現的,那麼我簡單介紹一下實現的方法,是我在項目開發中的一個,其中上方顏色值為#e8e8e8,下方顏色值為#dbdbdb,想要實現漸層並且在漸層的結束有一條明顯的線,那麼就需要漸層結束時的顏色略深於dbdbdb就OK了,

                  

 

在drawable中建立一個test_gradient.xml檔案內容如下:

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle" >    <gradient        android:angle="270"        android:endColor="#b9b9b9"        android:startColor="#e8e8e8" /></shape>

 

然後用法如下:

 

    <ImageView        android:layout_width="fill_parent"        android:layout_height="10dip"        android:background="@drawable/test_gradient" />

 

 

OK了,我的endColor略深於下面的顏色dbdbdb,這樣漸層結束的時候會有一條明顯的線,如果不想要這個線,則把endColor設定成dbdbdb,就OK~。gradient中的angle指的是漸層顏色的角度,改成90,180,270,大家分別自己試一試效果吧,我就不了。

相關文章

聯繫我們

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