package tori.test.viewtest;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.os.Bundle;
import android.view.View;
import android.widget.ScrollView;
import android.widget.Toast;

public class ViewTest extends Activity {
 static Integer height;
 static Integer width;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     //get height and width of screen
     height = this.getResources().getDisplayMetrics().heightPixels;
     width = this.getResources().getDisplayMetrics().widthPixels;
     //create views
     ScrollView sv = new ScrollView(this);
     CustomView cv = new CustomView(this);
     //add custom view with drawn rectangle to scrollview
     sv.addView(cv);
     //set content view as scrollview
     setContentView(sv);

     CharSequence output = height.toString() + "..." + width.toString();
     Toast.makeText(getApplicationContext(), output, Toast.LENGTH_SHORT)
     .show();

 }

 private static class CustomView extends View {


     public CustomView(Context context) {
         super(context);
         // TODO Auto-generated constructor stub
     }

     protected void onDraw(Canvas canvas) {
         ShapeDrawable rect = new ShapeDrawable(new RectShape());
         rect.getPaint().setColor(0xFFFF0000);
         rect.setBounds(50, 50, width - 100, height - 100);
         rect.draw(canvas);
     }

 }
}

 

 

왜그럴까요??스크롤 없이는 CustomView가 잘나오거든요..ㅠㅠ

신입 개발자입니다. ~