Android 在Imageview的evey touch坐标上绘制图像
我想在android中用户接触现有图像视图的每个点绘制小圆形图像。我想处理每个小绘图图像的点击。现在我正在尝试在ImageView上绘制圆形图像,但它对我不起作用 这是我的密码:Android 在Imageview的evey touch坐标上绘制图像,android,image,ontouchlistener,android-bitmap,Android,Image,Ontouchlistener,Android Bitmap,我想在android中用户接触现有图像视图的每个点绘制小圆形图像。我想处理每个小绘图图像的点击。现在我正在尝试在ImageView上绘制圆形图像,但它对我不起作用 这是我的密码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
<?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类:
package com.example.htmlcheck;
导入java.util.ArrayList;
导入android.content.Context;
导入android.graphics.Bitmap;
导入android.graphics.BitmapFactory;
导入android.graphics.Canvas;
导入android.graphics.Paint;
导入android.graphics.Point;
导入android.util.AttributeSet;
导入android.view.MotionEvent;
导入android.widget.ImageView;
公共类CustomImageView扩展了ImageView{
私人ArrayList mTouches;
私有位图标记器;
//Java构造函数
公共CustomImageView(上下文){
超级(上下文);
init();
}
//XML构造函数
公共CustomImageView(上下文、属性集属性){
超级(上下文,attrs);
init();
}
私有void init(){
mTouches=newarraylist();
mMarker=BitmapFactory.decodeResource(this.getResources(),
R.可拉拔。十字(小);
}
@凌驾
公共布尔onTouchEvent(运动事件){
//为绘图捕获每个触摸的参考
if(event.getAction()==MotionEvent.ACTION\u向下){
添加(新点((int)event.getX(),(int)event.getY());
返回true;
}
返回super.onTouchEvent(事件);
}
@凌驾
受保护的void onDraw(画布c){
//让我们先画图像
super.onDraw(c);
//在此处绘制自定义点
油漆=新油漆();
对于(点p:mTouches){
c、 绘图位图(mMarker、p.x、p.y、油漆);
}
}
}
给你:-
mImgBigImageview.setOnTouchListener(新的OnTouchListener(){
@凌驾
公共布尔onTouch(视图v,运动事件){
CustomImageView mcustomImagview=(CustomImageView)v;
mcustomImagview.invalidate();
如果(v.事件){
//对event.getX()和event.getY()执行某些操作
}
返回true;
}
});
Hi sid,谢谢你的帮助,你能告诉我现在可以点击打印图像的方式吗,这样我就可以在每一张可点击的打印图像上打开diaolge。我真的在尝试我的水平节拍来实现这一点,但不能……我是android新手