A sentimental robot

My xml 본문

Android Studio

My xml

GOD03219 2018. 2. 6. 15:20
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.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.AttributeSet;
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 flag = 0;

public Tiger(Context context) {
super(context);
}

public Tiger(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public Tiger(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(Color.RED);

canvas.drawRect(10 - flag, 20 - flag, 30 + flag, 40 + flag, paint);

}
void inC(){
flag+=20;
invalidate();

}
void deC(){
flag-=20;
invalidate();
}

}

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void f1(View view) {
Tiger tiger = findViewById(R.id.cv);
tiger.inC();

}

public void f2(View view) {
Tiger tiger = findViewById(R.id.cv);
tiger.deC();

}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.i310_54.myapplication08.MainActivity"
android:orientation="vertical"
android:weightSum="1"
>


<com.example.i310_54.myapplication08.Tiger
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:id="@+id/cv"
/>

<Button
android:id="@+id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UPSIZING"
android:onClick="f1"
/>
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="downSizing"
android:onClick="f2"
/>

</LinearLayout>

'Android Studio' 카테고리의 다른 글

Menu  (0) 2018.02.07
Thread를 이용한 UI  (0) 2018.02.07
Customizing  (0) 2018.02.06
OnTouch  (0) 2018.02.06
RelativeLayout  (0) 2018.02.06