Android設定簡單的動畫效果
阿新 • • 發佈:2021-06-26
Android設定簡單的動畫效果
預設中,Button是有動畫效果的,但是TextView等卻沒有,簡單設定其動畫效果如下
xml中新增
android:background="?android:attr/selectableItemBackground"
背景效果
android:foreground="?android:attr/selectableItemBackground"
前景效果
這樣便能簡單設定了觸碰效果
android:background="?android:attr/selectableItemBackgroundBorderless" <!--無邊界漣漪效果--> android:background="?android:attr/selectableItemBackground" <!--有邊界漣漪效果-->
foreground屬性只能給控制元件和幀佈局設定,其它的佈局設定無效果
也可以自己建立效果
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/abc_list_selector_disabled_holo_light" /> <item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/abc_list_selector_disabled_holo_light" /> <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/abc_list_selector_background_transition_holo_light" /> <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/abc_list_selector_background_transition_holo_light" /> <item android:state_focused="true" android:drawable="@drawable/abc_list_focused_holo" /> <item android:drawable="@android:color/transparent" /> </selector>
相關屬性:
android:state_selected 選中
android:state_focused 獲得焦點
android:state_pressed 點選
android:state_enabled 設定是否響應事件,指所有事件
android:drawable 設定圖片效果