일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 토큰경제
- html plug-in
- #JAVASCRIPT
- #binary
- html5 new tag
- #다차원포인터
- #bubbleSort
- #C++ 연산자함수오버로딩
- hyperledger transaction
- html code
- mac terminal command
- border-box
- relative path
- html id
- html charset
- #CallByAddress
- #C++ has~a
- 하이퍼레저패브릭
- html youtube
- html video
- html object
- #자바상속#자바이즈어#is~a
- html multimedia
- #android activity
- #성적관리프로그램
- #2차원배열
- #1차원배열
- docker example
- git flow
- #3차원배열
Archives
- Today
- Total
A sentimental robot
Customizing 본문
package com.example.i310_54.myapplication08;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import java.util.Random;
class Tiger extends View {
public Tiger(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint=new Paint(); // Create a tool to draw
paint.setColor(Color.RED);
//Canvas is where I draw
canvas.drawRect(100,200,300,400,paint); //draw a rectangle
}
}
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
Tiger tiger = new Tiger(this);
setContentView(tiger);
}
}
package com.example.i310_54.myapplication08;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import java.util.Random;
class Tiger extends View {
int x=0;
public Tiger(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(Color.RED);
x+=20;
canvas.drawRect(100-x, 200-x, 300+x, 400+x, paint);
}
}
public class MainActivity extends AppCompatActivity {
String TAG = "EUN";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
final Tiger tiger = new Tiger(this);
setContentView(tiger);
tiger.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN) {
v.invalidate(); // invalidate 함수는 무조건 onDraw call
}
return false;
}
});
}
}
'Android Studio' 카테고리의 다른 글
Thread를 이용한 UI (0) | 2018.02.07 |
---|---|
My xml (0) | 2018.02.06 |
OnTouch (0) | 2018.02.06 |
RelativeLayout (0) | 2018.02.06 |
Handler (0) | 2018.02.05 |