开发者

How to translate a button from its relative position to the bottom of the screen?

开发者 https://www.devze.com 2023-02-27 19:03 出处:网络
I would like to translate a button from its relative position to the bottom of the screen. I am doing the TranslateAnimation usi开发者_StackOverflowng Java code.

I would like to translate a button from its relative position to the bottom of the screen.

I am doing the TranslateAnimation usi开发者_StackOverflowng Java code.

The following is the code snippet of what I've already did:

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

The result is that the button fly outside of the emulator screen!! :(

Thanks in advance for your help.


You could try something like this:

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());

to make sure it gets to the end of your screen.
x and y denote the current position of your Button.


you can avoid the button traslation out of the screen in this way(peseudo code):

traslation= screenheight-(actualButtonposition.y)

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

精彩评论

暂无评论...
验证码 换一张
取 消