mainactivity.java
package com.example.suidong1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
public class MainActivity extends Activity {
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
FrameLayout framelayout = (FrameLayout) findViewById (R.id.mlayout); l
final RabbitView rabbit = new RabbitView (MainActivity.this);
rabbit. setOnTouchListener (new OnTouchListener () {
@ Override
public boolean onTouch (View v, MotionEvent event) {
/ / TODO Auto-generated method stub
rabbit.bitmapX = event.getX ();
rabbit.bitmapY = event.getY ();
rabbit.invalidate ();
return true;
}
});
framelayout.addView (rabbit);
}
@ Override
public boolean onCreateOptionsMenu (Menu menu) {
/ / Inflate the menu; this adds items to the action bar if it is present
.getMenuInflater () inflate (R.menu.main, menu);.
return true;
}
}
rabbitview class
RabbitView.java
public class RabbitView extends View {
public float bitmapX;
public float bitmapY;
public RabbitView (Context context) {
super (context);
/ / TODO Auto-generated constructor stub
bitmapX = 750;
bitmapY = 500;
}
@ SuppressLint ("DrawAllocation")
@ Override
protected void onDraw (Canvas canvas) {
/ / TODO Auto-generated method stub
super.onDraw (canvas);
Paint paint = new Paint ();
Bitmap bitmap = BitmapFactory.decodeResource (this.getResources (), R.drawable.rabbit);
canvas.drawBitmap (bitmap, bitmapX, bitmapY, paint);
if (bitmap.isRecycled ()) {
bitmap.recycle ();
}
}
Problems in Miaohong position prompted the alert after clicking Yes. Type View method setOnTouchListener (View.OnTouchListener) for parameter (new OnTouchListener () {}) NA
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Solve the problem, import the class less, eclipse prompted to import less, it seems the future is not entirely based on software error correction
No comments:
Post a Comment