Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyCustomView extends View
- {
- Context ctx;
- public MyCustomView(Context context, AttributeSet attrs) {
- super(context);
- // TODO Auto-generated constructor stub
- ctx=context;
- }
- @Override
- public void onDraw(Canvas canvas) {
- // TODO Auto-generated method stub
- canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.layout1), 0, 0,null);
- //Log.i("Canvs Length",canvas.getWidth()+" "+canvas.getHeight()); Returns the screen coordinates
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- // TODO Auto-generated method stub
- //return super.onTouchEvent(event);
- Log.i("MotionEvent ",event.getX()+" "+event.getY());
- Toast.makeText(ctx,event.getRawX()+" "+event.getRawY() , Toast.LENGTH_SHORT).show();
- return true;
- }
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- // TODO Auto-generated method stub
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- }
- }
- Layout file :
- <?xml version="1.0" encoding="utf-8"?>
- <view xmlns:android="http://schemas.android.com/apk/res/android"
- class="com.android.mycustomview.MyCustomView"
- android:id="@+id/SurfaceView01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:maxHeight="40dip"
- android:background="#ff0000">
- </view>
Advertisement
Add Comment
Please, Sign In to add comment