【问题标题】:Android layout animationAndroid布局动画
【发布时间】:2015-06-15 21:41:24
【问题描述】:

我在布局底部有一个按钮,单击该按钮时,该按钮应移至顶部(距顶部 48 DP 边距)。 如何做到这一点,请帮忙。

【问题讨论】:

标签: android android-animation


【解决方案1】:

将此 move.xml 放在 anim 文件夹中

<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">

<translate
android:fromYDelta="0%p"
android:toYDelta="-80%p"
android:duration="800" />
</set>

并使用此代码为该按钮设置动画

// Animation
final Animation move_anim =   AnimationUtils.loadAnimation(this,R.anim.move);

并将其放入您的 onclick 事件中

btn.startAnimation(move_anim)

【讨论】:

  • 如何在这 75% 中给出 48 dp 的边距?
  • 不需要在此动画 .xml 中设置边距,如果仍然无法获得它,您可以保留主要 .xml 中的边距。.. :)
猜你喜欢
  • 1970-01-01
  • 2012-01-25
  • 2016-08-25
  • 2014-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-01
相关资源
最近更新 更多