在 Imageview 的每个触摸坐标上绘制图像

Draw images on evey touch co-ordinats Of Imageview

我想在用户触摸现有图像视图的每个点绘制小圆形图像 android.And 想要处理每个小绘图的点击 image.Right 现在我正在尝试绘制圆形图像在 ImageView 上,但它对我不起作用。

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    android:orientation="vertical"
    android:weightSum="2" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".5"
        android:background="#EEEDEE"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="20dp"
        android:weightSum="4" >

        <ImageView
            android:id="@+id/img_overview"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@null"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/img_specifications"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:background="@null"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/img_features"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:background="@null"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/img_resources"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:background="@null"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.5" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#FFFFFF"
            android:orientation="vertical"
            android:padding="20dp" >

            <Textview
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Siss "
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="#CE561B"
                android:textStyle="bold|italic" />

            <Textview
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="30dp"
                android:text="dummy long text"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="@color/black_color" />

             <FrameLayout
            android:id="@+id/ll_img_bigview_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <com.example.htmlcheck.CustomImageView
                android:id="@+id/img_big_imageview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="@drawable/sj"/>
        </FrameLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

sj 图片的尺寸为 900 X 600 像素。

我的 CustomImageView Class :

package com.example.htmlcheck;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageView;

public class CustomImageView extends ImageView {

 private ArrayList<Point> mTouches;
 private Bitmap mMarker;

 // Java constructor
 public CustomImageView(Context context) {
  super(context);
  init();
 }

 // XML constructor
 public CustomImageView(Context context, AttributeSet attrs) {
  super(context, attrs);
  init();
 }

 private void init() {
  mTouches = new ArrayList<Point>();
  mMarker = BitmapFactory.decodeResource(this.getResources(),
    R.drawable.cross_small);
 }

 @Override
 public boolean onTouchEvent(MotionEvent event) {
  // Capture a reference to each touch for drawing
  if (event.getAction() == MotionEvent.ACTION_DOWN) {
   mTouches.add(new Point((int) event.getX(), (int) event.getY()));
   return true;
  }

  return super.onTouchEvent(event);
 }

 @Override
 protected void onDraw(Canvas c) {
  // Let the image be drawn first
  super.onDraw(c);

  // Draw your custom points here
  Paint paint = new Paint();
  for (Point p : mTouches) {
   c.drawBitmap(mMarker, p.x, p.y, paint);
  }
 }

}

我的 activity :

public class MainActivity extends Activity implements OnClickListener {

 private CustomImageView mImgBigImageview;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  mImgBigImageview = (CustomImageView) findViewById(R.id.img_big_imageview);
  
        mImgBigImageview.setOnTouchListener(new OnTouchListener() {

   @Override
   public boolean onTouch(View v, MotionEvent event) {
    
    if (v.onTouchEvent(event)) {
     
    }
    return true;
   }
  });
 }

任何帮助将不胜感激。 谢谢

给你:-

mImgBigImageview.setOnTouchListener(new OnTouchListener() {

   @Override
   public boolean onTouch(View v, MotionEvent event) {
    CustomImageView mcustomImagview = (CustomImageView) v;
    mcustomImagview.invalidate();
    if (v.onTouchEvent(event)) {
     // Do something with event.getX(), event.getY()
    }
    return true;
   }
  });