就像我的代码一样,但这有错误的线程折旧方法
class x implements Threads{
public void run()
{
someButton.layout(10,k,40,40);
k+=10;
}}
答案 0 :(得分:0)
为什么不在Android中尝试Inbuilt Animations
如果你们都想要移动对象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);
}
}
答案 1 :(得分:0)
是的,我们可以但你必须使用用户界面线程
runOnUiThread(new Runnable() {
@Override
public void run() {
// do your stuff here
}
});