こんにちは、私は 1 つのカスタム フレーム レイアウト クラスを使用している Android アプリケーションを開発しています。そのクラス内で、私は1つのドローアブルを使用しており、キャンバスの助けを借りてそれを描いています。私は次の方法でこれを行いました:
public class BackgroundContainer extends FrameLayout implements OnTouchListener{
Drawable mShadowedBackground;
public BackgroundContainer(Context context) {
super(context);
init();
}
public BackgroundContainer(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public BackgroundContainer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
mShadowedBackground =
getContext().getResources().getDrawable(R.drawable.actionbar);
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
Log.i("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", "OOOOOOOOOOOOOOOOOOOOOO");
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN: {
invalidate();
}
}
return true;
}
@Override
protected void onDraw(Canvas canvas) {
mShadowedBackground.setBounds(getWidth()-150, 0, getWidth(), mOpenAreaHeight);
canvas.save();
canvas.translate(0, mOpenAreaTop);
mShadowedBackground.draw(canvas);
canvas.restore();
}
}
}
今、私は自分のドローアブルでもクリックを聞きたいと思っています。ontouch イベントを実装しましたが、機能しません。私は間違った方法でそれをやっていますか?助けが必要ですありがとう。