有谁知道我会怎么做?而且imageView应该来自活动之外。
以下是代码:
rollingImageView =(ImageView)findViewById(R.id.imageView1);
AnimationSet rollingIn = new AnimationSet(true);
Animation moving = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,-1f,Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0);
moving.setDuration(5000);
rollingIn.addAnimation(moving);
Animation rotating = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotating.setDuration(5000);
rollingIn.addAnimation(rotating);
rollingImageView.startAnimation(rollingIn);
答案 0 :(得分:1)
假设您将图像视图设置为左下角(这只会帮助您从左向右)
在您的活动档案中......
public void callthismethodtostartrolling(){
final Thread myThread = new Thread(new Runnable()
{
@Override
public void run()
{
while (!<imageviewInRightCorner>) {//<<define this yourself
try {
Thread.sleep(4);
runOnUiThread(new Runnable()
{
@Override
public void run() {
rollingImageView.setX((float) (rollingImageView.getX() + 5));
}
});
} catch (InterruptedException e) {
// this should not happen
}
}
}
});
myThread.start
}
<强>赞成强>
我认为它会产生你想要的效果。
<强> CONS 强>
我之前尝试过这个,它可以工作,但如果你需要这样做,你就不能打断线程内的线程。如果您想帮助Dusan和我,那么原始问题/ con的链接是here。
<强> ALTERNATIVE 强>
final Thread myThread = new Thread(new Runnable()
{
@Override
public void run()
{
while (!<imageviewInRightCorner>) {//<<define this yourself
try {
Thread.sleep(4);
runOnUiThread(new Runnable()
{
@Override
public void run() {
rollingImageView.setX((float) (rollingImageView.getX() + 5));
}
});
} catch (InterruptedException e) {
// this should not happen
}
}
}
});
在代码中的任意位置使用myThread.start
来激活您的滑动镜像视图非常棒。
<强>赞成强>
替代第一个选项,使用不同的con以满足您的需求
*能够在线程中使用myThread.interrupt
<强> CONS 强>
每次发布时不能多次调用线程:/原因全在here
条件解释时(根据提问者的要求)......