안드로이드 개발 질문/답변
(글 수 45,052)
HUD를 한번 만들어보고 있는데요, 화면전환을 Animation의 rotate를 이용하여 Layout의 상하좌우를 반전하였습니다.
이렇게 해두고 테스트를 위해서 Thread와 Handler를 사용해서 TextView의 문자열을 setText로 변경해보았는데 바뀌질 않더군요.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha
android:fromAlpha="1.0"
android:toAlpha="1.0"
android:duration="100" />
<scale
android:fromXScale="1.0"
android:toXScale="-1.0"
android:fromYScale="1.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="400" />
<rotate
android:fromDegrees="0"
android:toDegrees="-180"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="400" />
</set>이렇게 해두고 테스트를 위해서 Thread와 Handler를 사용해서 TextView의 문자열을 setText로 변경해보았는데 바뀌질 않더군요.
package Test.primium;
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
public class Main extends Activity {
TextView testText;
Animation rotate;
RelativeLayout rl;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
testc = (Button) findViewById(R.id.testc);
testText = (TextView) findViewById(R.id.testText);
rl = (RelativeLayout) findViewById(R.id.turntest);
rotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch(msg.arg1){
case 0:
//testc.setText("number: " + i);
testc.appendText("number: " + i + " ");
Toast.makeText(Main.this, "number: " + i, Toast.LENGTH_SHORT).show();
}
}
};
testc.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
setAnimation(rotate);
Thread t = new Thread(){
public void run(){
while(true){
int i = (int)(Math.random() * 10);
mHandler.obtainMessage(0, 0, 0, i).sendToTarget();
try{
Thread.sleep(500);
}catch(Exception e){
}
}
}
};
t.start();
}
});
}
void setAnimation(Animation animation){
animation.setFillAfter(true);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
});
rl.startAnimation(animation);
}
}
혹시 값이 넘어가지 않는걸까 해서 append와 Toast로 해보았습니다만 문자열이 붙는것을 확인, 토스트에 나오는 값도 잘 나오더군요.
다만.. 끊겨서 추가된다든지, 텍스트가 깨져서 나온다든지 같이 약간은 정상적이지 못하게 나오더군요.
반전된 Layout 안의 아이템들을 정상적으로 갱신시키려면 어떤 방법이 있는지 전문가분들에게 조심스레 여쭤봅니다.




시일이좀 지났는데 해결하셨을라나요? 못하셨음 댓글 ㄱㄱ