@Override
public
View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if
(mView ==
null
) {
mView = inflater.inflate(R.layout.img_main, container,
false
);
ibtn1 = (Button) mView.findViewById(R.id.btn1);
ibtn2 = (Button) mView.findViewById(btn2);
try
{
image2 = (ImageView) mView.findViewById(image);
String imgpath =
"/sdcard/Download/test.jpg"
;
Bitmap bm = BitmapFactory.decodeFile(imgpath);
image2.setImageBitmap(bm);
Toast.makeText(mParent,
"load ok"
, Toast.LENGTH_SHORT).show();
}
catch
(Exception e) {
Toast.makeText(mParent,
"load error"
, Toast.LENGTH_SHORT).show();
}
image2.setOnTouchListener(
new
View.OnTouchListener() {
@Override
public
boolean
onTouch(View v, MotionEvent event) {
String action =
""
;
switch
(event.getAction()) {
case
MotionEvent.ACTION_DOWN:
action =
"ACTION_DOWN"
;
x = (
int
) event.getX();
y = (
int
) event.getY();
onDraw();
break
;
case
MotionEvent.ACTION_MOVE:
break
;
case
MotionEvent.ACTION_UP:
break
;
}
Log.v(
"MotionEvent"
,
"action = "
+ action +
", "
+
"x = "
+ String.valueOf(event.getX()) +
", "
+
"y = "
+ String.valueOf(event.getY()));
return
true
;
}
public
void
onDraw() {
Paint paint =
new
Paint();
Canvas canvas =
new
Canvas();
canvas.drawRect(x, y, x +
100
, y +
100
, paint);
paint.setColor(Color.RED);
}
});