add ripple effect

This commit is contained in:
tibbi 2016-03-22 19:16:02 +01:00
parent e160894144
commit 9dfe89ba6b
4 changed files with 31 additions and 55 deletions

View file

@ -1,46 +0,0 @@
package com.simplemobiletools.gallery;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
public class MyRelativeLayout extends RelativeLayout {
private Drawable mForegroundSelector;
public MyRelativeLayout(Context context) {
super(context);
}
public MyRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
{
mForegroundSelector = getResources().getDrawable(R.drawable.selector);
}
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
mForegroundSelector.setState(getDrawableState());
invalidate();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mForegroundSelector.setBounds(0, 0, w, h);
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
mForegroundSelector.draw(canvas);
}
}

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<selector>
<item
android:drawable="@color/activated_item_foreground"
android:state_activated="true"/>
</selector>
</item>
<item>
<ripple android:color="@color/pressed_item_foreground">
<item android:id="@android:id/mask">
<color android:color="@android:color/white"/>
</item>
</ripple>
</item>
</layer-list>

View file

@ -1,14 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.gallery.MyRelativeLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/selector">
android:layout_height="match_parent">
<com.simplemobiletools.gallery.MyImageView
android:id="@+id/dir_thumbnail"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
android:foreground="@drawable/selector">
<com.simplemobiletools.gallery.MyImageView
android:id="@+id/dir_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
@ -35,4 +40,4 @@
android:textColor="@android:color/white"/>
</RelativeLayout>
</com.simplemobiletools.gallery.MyRelativeLayout>
</RelativeLayout>

View file

@ -5,6 +5,6 @@
<color name="colorAccent">#FF4081</color>
<color name="tmb_background">#ff222222</color>
<color name="actionbar_grey">#66000000</color>
<color name="pressed_item_foreground">#11000000</color>
<color name="activated_item_foreground">#44000000</color>
<color name="pressed_item_foreground">#33000000</color>
<color name="activated_item_foreground">#66000000</color>
</resources>