2012-06-07 4 views
1

이 좋아하는 스레드와 안드로이드의 모든 개체를 이동할 수있는 것은 내 코드하지만이우리가

class x implements Threads{ 
public void run() 
{ 
someButton.layout(10,k,40,40); 

k+=10; 
}} 
+2

는 정말'구현이 스레드?' –

+0

그는'Threads' – Lucifer

+0

스레드라는 클래스 경우에만 가능할 수있다! !!!!!!!!! 또는 스레드? –

답변

0

우리가 할 수있는 네하지만 사용자 인터페이스 스레드를 사용해야하는 이유는

runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          // do your stuff here 
         } 
       }); 
0

왜 당신은 안드로이드

에 붙박이 애니메이션을하지 마십시오 스레드의 감가 상각 방법의 가진 오류가 발생하면 모든 경우 원은

TranslateAnimation

object.setFillAfter(true); 그렇지 않으면 개체가 다시 원래 위치로 올 것이다 넣어 잊지 마세요 객체 사용을 이동하는 것입니다.

이하 스 니펫이 도움이 될 것입니다.

package org.sample; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.animation.TranslateAnimation; 
import android.widget.Button; 
import android.widget.LinearLayout; 
import android.widget.LinearLayout.LayoutParams; 
import android.widget.TextView; 

public class AnimationActivity extends Activity 
{ 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     LinearLayout ll = new LinearLayout(this); 
     ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 
       LayoutParams.MATCH_PARENT)); 
     ll.setOrientation(LinearLayout.VERTICAL); 

     final TextView tv = new TextView(this); 
     tv.setText("Animation"); 

     final TranslateAnimation moveLefttoRight = new TranslateAnimation(0, 
       200, 0, 0); 
     moveLefttoRight.setDuration(1000); 
     moveLefttoRight.setFillAfter(true); 

     Button button = new Button(this); 
     button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
       LayoutParams.WRAP_CONTENT)); 
     button.setText("PressMe"); 
     button.setOnClickListener(new OnClickListener() 
     { 

      public void onClick(View v) 
      { 
       tv.startAnimation(moveLefttoRight); 
      } 

     }); 

     ll.addView(tv); 
     ll.addView(button); 
     setContentView(ll); 

    } 
}