0

ボタンを押したときにリップルエフェクトを再生しようとしていますが、スタックオーバーフローやウェブ上で多くのガイドをたどりましたが、成功しませんでした。誰かが私を正しい方向に向けることができますか?私のXMLは正しいと思われますが、ボタンをクリックすると何も起こりません。画像ボタン上のリップルアニメーション

ありがとうございました!

Ripple_animation.xml

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

<!-- thanks to http://www.viralandroid.com/2015/09/how-to-add-ripple-effect-to-android-button.html !--> 

<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:color="@color/ripple_Orange" 
    tools:targetApi="lollipop"> 
    <item android:id ="@android:id/mask"> 
     <shape android:shape="rectangle"> 
      <solid android:color = "@color/ripple_Orange"/> 
     </shape> 
    </item> 

</ripple> 

あなたはbackground属性としてリップルを設定するボタンに

<ImageButton 
     android:id="@+id/one_button" 
     android:background="@drawable/ripple_animation" 
     android:padding="0dp" 
     android:adjustViewBounds="true" 
     android:scaleType="fitXY" 
     android:layout_width="85dp" 
     android:layout_height="85dp" 
     app:srcCompat="@drawable/one_button_500_500" 
     android:layout_below="@+id/four_button" 
     android:layout_alignParentStart="true" /> 
+1

これを試してみてください上に描かれる。フォアグラウンドの属性または親のフォアグラウンドとして試してください – RobCo

+0

@RobCoうまくいきました、ありがとうございました!コメントではなく回答としてあなたの回答を再提出できますか、私はあなたに適切なクレジットを与えたいと思います。 – Lontronix

答えて

1

を波及効果を適用します。
つまり、画像srcの後ろに描画されます。

は代わりに、このビューの前景として、それを設定するか、それは親の:

android:foreground="@drawable/ripple_animation" 
1

srcがあるので、リップルが背景としてあるデバイスのデフォルトの波及効果を示すために

<?xml version="1.0" encoding="utf-8"?> 
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:foreground="?android:selectableItemBackground"> 

     <ImageButton 
      android:id="@+id/one_button" 
      android:background="@drawable/ripple_animation" 
      android:padding="0dp" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:layout_width="85dp" 
      android:layout_height="85dp" 
      app:srcCompat="@drawable/one_button_500_500" 
      android:layout_below="@+id/four_button" 
      android:layout_alignParentStart="true" /> 
    </FrameLayout>