我試圖通過我在drawable中創建的自定義xml文件在我的應用中實現漣漪效應。現在,它只適用於運行棉花糖或以上的設備而不是棒棒糖(api 21 & api 22)。這是自定義的xml文件。波紋效果不適用於棒棒糖,但適用於棉花糖及以上
RES /繪製-V21/ripple_effect.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#ff0000"
tools:targetApi="LOLLIPOP">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#ff0000" />
</shape>
</item>
這是我的主要活動XML
佈局/ activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="true"
android:foreground="@drawable/ripple_effect"
android:src="@drawable/background3360" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#333"
android:foreground="@drawable/ripple_effect"
android:text="This is a Button"
android:textColor="#fff" />
</LinearLayout>
現在啓動後,我可以清楚地看到一個漣漪效應(紅色)在imageView和按鈕上,但在棒棒糖設備上,我沒有看到這種效果。我的猜測是,這是因爲android:foreground
,它不知道在除棒棒糖framelayout
以外的佈局。以上棒棒糖android:foreground
適用於各種佈局/視圖。我想在此linearlayout
和imageView
以及棒棒糖設備中通過xml實現此自定義連鎖反應。
你是正確的,Android的:不支持在大多數的Android版本的標準視圖前景。但是,您可以創建支持此屬性的自定義ImageView,也可以將ImageView包裝在支持該屬性的FrameLayout中。 – BladeCoder