2011-04-22 34 views
0

我想将一个按钮从其相对位置翻译到屏幕底部。如何将按钮从相对位置转换到屏幕底部?

我在做使用Java代码的TranslateAnimation。

下面是什么我已经做了代码片段:

Display display = getWindowManager().getDefaultDisplay(); 
int screenHeight = display.getHeight(); 
translateButtonAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, height); 

结果是按钮飞行模拟器的屏幕之外! :(

在此先感谢您的帮助

回答

0

就可以避免按钮翻译中移出屏幕以这种方式(peseudo代码):

traslation= screenheight-(actualButtonposition.y) 

translateButtonAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, height); 
+0

对不起,它没有工作。 – 2011-04-23 10:19:00

1

你可以尝试这样的事:

Animation toBottom = 
    new TranslateAnimation(
      Animation.RELATIVE_TO_PARENT, x, 
      Animation.RELATIVE_TO_PARENT, 0.0f, 
      Animation.RELATIVE_TO_PARENT, -1.0f, 
      Animation.RELATIVE_TO_PARENT, 0.0f); 
toBottom.setDuration(350); 
toBottom.setInterpolator(new AccelerateInterpolator()); 

,以确保它到达屏幕的结束。
xy德注意您的当前位置Button

+0

对不起,它没有工作。 – 2011-04-23 10:17:39

+3

然后请为您的源代码布局提供您所需的准确翻译描述,并且不要让我们猜测您可能已经拥有的内容,并且需要遵守(因为此代码和@ Kevin's在一个简单的“RelativeLayout” )。谢谢! – rekaszeru 2011-04-23 10:30:56

相关问题