Advertisement
danh8569

ASproject

Feb 23rd, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. Button obs;
  2. TextView tv;
  3.  
  4.     @Override
  5.     protected void onCreate(Bundle savedInstanceState) {
  6.         super.onCreate(savedInstanceState);
  7.         setContentView(R.layout.activity_main);
  8.  
  9.         obs = (Button) findViewById(R.id.obs);
  10.         tv = (TextView) findViewById(R.id.tv);
  11.  
  12.         obs.setOnClickListener(this);
  13.     }
  14.  
  15.     @Override
  16.     public void onClick(View view) {
  17.         if(view == obs){
  18.  
  19.         }
  20.     }
  21.  
  22. //main class ^^^
  23.  
  24. public class Obstacle extends View {
  25.     Context context;
  26.     private Bitmap rock_1;
  27.  
  28.     public Obstacle(Context context){
  29.         super(context);
  30.         this.context = context;
  31.         init(null);
  32.     }
  33.  
  34.     public Obstacle(Context context, AttributeSet attr){
  35.         super(context, attr);
  36.         this.context = context;
  37.         init(attr);
  38.     }
  39.  
  40.     private void init(@Nullable AttributeSet attr){
  41.         rock_1 = BitmapFactory.decodeResource(getResources(), R.drawable.rock_1);
  42.         //rock_1 = getResizedBitmap(rock_1, getWidth(), getHeight());
  43.     }
  44.  
  45.     @Override
  46.     protected void onDraw(Canvas canvas) {
  47.         super.onDraw(canvas);
  48.         canvas.drawBitmap(rock_1, 0, 0, null);
  49.     }
  50.  
  51.     /*private Bitmap getResizedBitmap(Bitmap bitmap, int width, int height){
  52.         Matrix matrix = new Matrix();
  53.         RectF source = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
  54.         RectF dest = new RectF(0, 0, width, height);
  55.         matrix.setRectToRect(source, dest, Matrix.ScaleToFit.CENTER);
  56.         return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
  57.     }*/
  58. }
  59.  
  60. //class obstacle ^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement