之Ripple水波紋效果

android 5.0 擁有ripple效果, 非常漂亮
這裏寫圖片描述
具體使用方法如下:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#ffff0000">
    <item android:drawable="@color/blue"></item> // 如果不要這個行, 則ripple效果溢出
</ripple>

或者

<?xml version="1.0" encoding="utf-8"?>
<ripple
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@android:color/holo_blue_dark">
    <item> // 這個item中包含你的drawable資源即可
        <shape
            android:shape="oval">
            <solid android:color="@android:color/holo_orange_dark" />
        </shape>
    </item>
</ripple>

官方示例:

 <!-- A red ripple masked against an opaque rectangle. --/>
 <ripple android:color="#ffff0000">
   <item android:id="@android:id/mask"
         android:drawable="@android:color/white" />
 </ripple>

If a mask layer is set, the ripple effect will be masked against that layer before it is drawn over the composite of the remaining child layers.

If no mask layer is set, the ripple effect is masked against the composite of the child layers.

 <!-- A green ripple drawn atop a black rectangle. --/>
 <ripple android:color="#ff00ff00">
   <item android:drawable="@android:color/black" />
 </ripple>

 <!-- A blue ripple drawn atop a drawable resource. --/>
 <ripple android:color="#ff0000ff">
   <item android:drawable="@drawable/my_drawable" />
 </ripple>

上面的的文件定義在drawable資源中,設置成你控件的背景顏色就可以了

參考資料:
http://blog.csdn.net/ljx19900116/article/details/41806917
http://developer.android.com/reference/android/graphics/drawable/RippleDrawable.html(需要翻牆)

demo地址:
https://github.com/zhangyang3233/android21effect

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章