安卓:有没有什么办法让观的TranslateAnimation后的最新立场? [英] Android: Is there any way to get the latest position of View after TranslateAnimation?

查看:140
本文介绍了安卓:有没有什么办法让观的TranslateAnimation后的最新立场?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道多种方式来获取视图的位置值。

I know multiple ways to get location values of a View.

getLocationOnScreen()
getLocationInWindow()
getLeft()

然而,他们没有实际返回我搬到由startAnimation()方法查看当前位置,但只有原来的位置。

However, none of them actually returns the current location of the View I moved by startAnimation() method, but only the original location.

所以,现在让我们做一个观点,即由10个像素向右移动每次点击(我省略了布局,因为你可以放置在主XML无论大家认为,并给它onClickListener)。

So, now let's make a View that moves to the right by 10 pixels on each Click (I'm omitting the layout, since you can just place whatever view in your main XML and give it onClickListener).

public class AndroidTestActivity extends Activity implements OnClickListener {  
LinearLayout testView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    testView = (LinearLayout) this.findViewById(R.id.test);
    testView.setOnClickListener(this);
}

public void onClick(View v) {
    int[] pLoS = new int[2];
    testView.getLocationOnScreen(pLoS);
    TranslateAnimation move = new TranslateAnimation(pLoS[0], pLoS[0] + 10, 0f, 0f);
    move.setFillAfter(true);
    move.setFillEnabled(true);
    testView.startAnimation(move);
}

}

如你所见,这并不如我预期的工作,因为getLocationOnScreen()总是返回相同的值(在我的情况,0),doen't反映我TranslateAnimation使用的值...

As you see, this doesn't work as I intended, since getLocationOnScreen() always returns the same value (in my case, 0), and doen't reflect the value I used in TranslateAnimation...

任何想法?

推荐答案

假设你使用的是Android&LT; 3.0那么你的问题可能是类似的静脉我的我问<一个href=\"http://stackoverflow.com/questions/5886624/animation-setfillafter-before-do-they-work-what-are-they-for\">here.基本上动画从视图本身即Android的独立动画您查看的副本。这就是为什么 getLocationOnScreen()总是返回0。这并不是说已经移动(动画),它是移动(动画)副本的看法。如果你看到的答案我的问题这个问题已经在Android中的更高版本中得到解决。

Assuming you're using Android < 3.0 then your question may be in a similar vein to mine I asked here. Basically Animations are separate from the View itself i.e. Android animates a copy of your View. That is why getLocationOnScreen() always returns 0. It's not the view that has moved (animated) it was the copy that moved (animated). If you see the answers to my question this issue has been addressed in later versions of Android.

这篇关于安卓:有没有什么办法让观的TranslateAnimation后的最新立场?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆