我已经准备了一个自定义视图,其高度为x,宽度为y(通过扩展View实现)。此视图具有背景,在其中我绘制了可绘制对象。用户可以将该可绘制对象在其x和y限制内移动。现在,我想在按下和聚焦状态下添加涟漪效果。实际上,当此视图获得焦点时,我也无法将焦点集中在该可绘制对象上。
public class CustomView extends View {
Drawable image;
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
setFocusable(true);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.abc);
image = a.getDrawable(R.styleable.x);
mBackgroundImage = a.getDrawable(R.styleable.y);
this.setBackgroundDrawable(mBackgroundImage);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = image.getIntrinsicWidth();
int height = image.getIntrinsicHeight();
location = calculatePosition();
image.setBounds((int) location, 0, (int) (location + width), height);
image.draw(canvas);
}
}
我想在那个“image”上添加涟漪效果。我已经搜索了很多,但没有找到任何解决方案。然后我注册了stackoverflow,并发布了我的第一个问题。如果有人知道,请帮忙。
提前感谢。