자바 파일

package Test_part.main;
public class test_part extends Activity{
     private DrawLine dl;
     private int left = 20 , top = 20 , width = 10, height = 30;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.test);
          dl = (DrawLine)findViewById(R.id.image);
          dl.left = left; dl.top = top; dl.width = width; dl.height = height;
          test_draw td = new test_draw();
          td.start();
     }
     class test_draw extends Thread{
          int timer = 0;
          public void run(){
               while(timer != 30){
                    timer++;
                    height += 3; width += 2;
                    dl.height = height; dl.width = width;
                    dl = (DrawLine)findViewById(R.id.image);
                    try {
                    test_draw.sleep(1000);
                    } catch (InterruptedException e) {}
              }
         }
     }
}
class DrawLine extends View {
    Paint p = new Paint();
    int left , top , width , height;
    public DrawLine(Context context) {
     super(context);
    }
    public DrawLine(Context context, AttributeSet attrs) {
     super(context, attrs);
   }
    public DrawLine(Context context, AttributeSet attrs, int defStyle) {
     super(context, attrs, defStyle);
   }
    @Override 
    protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      LinearGradient lg1 = new LinearGradient(left, top, left + width, top + height,
       new int[]{Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE, Color.MAGENTA},
       new float[]{0.2f, 0.4f, 0.6f, 0.8f, 1f}, Shader.TileMode.MIRROR);
      p.setShader(lg1);
      canvas.drawRect(left, top, left + width, top + height, p);
    }
}

 

xml 파일

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF">
    <LinearLayout 
     android:id="@+id/ll"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="#FFFFFF">
         <Test_part.main.DrawLine
             android:id="@+id/image"
             android:layout_width="wrap_content"
             android:layout_height="150px"/>
    </LinearLayout>
</ScrollView>


커스텀 위젯을 만들어서 xml에 추가시키고 그 위젯은 커스텀뷰로 선을 그리는 간단한 예제인데요

 

커스텀 스레드를 이용해서 30초동안 1초마다 선에 width, height 가 점점 늘어나는 예제 입니다

 

근데 처음에 선을 그리고 매초마다 width, height 를 점점 늘려도 선이 다시 그려지지를 않고

 

30초가 지나서 커스텀 스레드가 끝나면 그때서야 30초동안 커진 width, height로 한번만 다시 그리더군요

 

그러니까 제가 원하는건

l     ll     lll     llll
      ll     lll     llll
             lll     llll
                    llll

이런식으로 선이 점점 커지는게 계속 다시 그려지는걸 원하는건데

l                    llll
                     llll
                     llll
                     llll

이렇게 처음과 끝 한번만  그려집니다ㅠㅠ

 

매초마다 바뀐 width, height로 계속 다시 그리게 하려면 어떻게 해야하는가요ㅠㅠ?

 

방법을 아시면 답변 꼭좀 부탁드립니다!