【问题标题】:How to translate a button from its relative position to the bottom of the screen?如何将按钮从其相对位置翻译到屏幕底部?
【发布时间】:2011-04-22 21:05:17
【问题描述】:

我想将一个按钮从它的相对位置翻译到屏幕底部。

我正在使用 Java 代码进行 TranslateAnimation。

以下是我已经做过的代码sn-p:

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

结果是按钮飞出模拟器屏幕!! :(

提前感谢您的帮助。

【问题讨论】:

    标签: android


    【解决方案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 的当前位置。

    【讨论】:

    • 那么请为您的源代码布局提供您想要的准确翻译描述,不要让我们猜测您可能已经拥有的内容,并且要跟上(因为这段代码和@Kevin's)在一个简单的RelativeLayout 中起作用)。谢谢!
    【解决方案2】:

    您可以通过这种方式避免按钮移出屏幕(伪代码):

    traslation= screenheight-(actualButtonposition.y)
    
    translateButtonAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, height);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-20
      相关资源
      最近更新 更多