0
如何設置onClickListener和onTouchListenere在android中的視圖類上?我如何設置onClickListener和onTouchListenere在android中的視圖類上的兩個
我的代碼:
package com.example.circledemo.second;
import java.util.ArrayList;
import android.app.Dialog; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.widget.ImageView; import android.widget.TextView;
import com.example.circledemo.R;
public class SecondTCanvas extends View {
public Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); Context contextData; int layoutWidth, layoutHeight;
private Bitmap canvasBitmap;
public SecondTCanvas(Context context, float[] values, int width, int height) { super(context); contextData = context; layoutHeight = height; layoutWidth = width;
System.out.println("=== Layout .... Width : " + layoutWidth + " Height : " + layoutHeight); }
public void onDraw(Canvas c) {
paint.setColor(Color.BLACK); c.drawRect(0, 0, getWidth(), getHeight(), paint); buildDrawingCache(true); canvasBitmap = getDrawingCache(true); }
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { // Get x and y coordinates of where the finger touched int pixelX = (int) (Math.floor(event.getX())); int pixelY = (int) (Math.floor(event.getY()));
if (canvasBitmap != null) { }
invalidate(); }
// If the finger is off the screen if (event.getAction() == MotionEvent.ACTION_UP) { // alphaIndex = -1; //This is a flag to reset the view alphas to // normal invalidate(); }
return true;
// return super.onTouchEvent(event); }
}
請解釋你的問題 – Lokesh