Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Button obs;
- TextView tv;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- obs = (Button) findViewById(R.id.obs);
- tv = (TextView) findViewById(R.id.tv);
- obs.setOnClickListener(this);
- }
- @Override
- public void onClick(View view) {
- if(view == obs){
- }
- }
- //main class ^^^
- public class Obstacle extends View {
- Context context;
- private Bitmap rock_1;
- public Obstacle(Context context){
- super(context);
- this.context = context;
- init(null);
- }
- public Obstacle(Context context, AttributeSet attr){
- super(context, attr);
- this.context = context;
- init(attr);
- }
- private void init(@Nullable AttributeSet attr){
- rock_1 = BitmapFactory.decodeResource(getResources(), R.drawable.rock_1);
- //rock_1 = getResizedBitmap(rock_1, getWidth(), getHeight());
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- canvas.drawBitmap(rock_1, 0, 0, null);
- }
- /*private Bitmap getResizedBitmap(Bitmap bitmap, int width, int height){
- Matrix matrix = new Matrix();
- RectF source = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
- RectF dest = new RectF(0, 0, width, height);
- matrix.setRectToRect(source, dest, Matrix.ScaleToFit.CENTER);
- return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
- }*/
- }
- //class obstacle ^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement