2011-04-22 32 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

相關問題