Android绝对布局/参数(在运行时移动小部件)

|| 因此,对于我正在从事的项目,我需要能够在运行时将小部件向上移动到屏幕上(例如反向瀑布)。有人可以显示一个示例,说明如何在运行时将按钮从屏幕的一个位置移动到更高的位置(使用绝对布局)吗? 我知道它可能会利用
 AbsoluteLayout.LayoutParams
params.addRule
。但请谨慎教我 例如: _____________________(屏幕顶部)                                        | [按钮]                                        | --                                        | --                                        | --                                        | --                                        | --                                        | --                                        | --                                        | >                                        | [按钮] _____________________(屏幕底部)     
已邀请:
来自http://developerlife.com/tutorials/?p=343 这是一个从左到右滑动的动画(在视图的宽度上从右向左平移),名为“ /res/anim/slide_right.xml”:
<?xml version=\"1.0\" encoding=\"utf-8\"?>

<set xmlns:android=\"http://schemas.android.com/apk/res/android\" android:interpolator=\"@android:anim/accelerate_interpolator\">
    <translate android:fromXDelta=\"100%p\" android:toXDelta=\"0\" android:duration=\"150\" />
</set>
这是另一个使用上面的动画序列(@ anim / slide_right.xml->“ /res/anim/slide_right.xml”):
<?xml version=\"1.0\" encoding=\"utf-8\"?>

<layoutAnimation xmlns:android=\"http://schemas.android.com/apk/res/android\"
        android:delay=\"10%\"
        android:order=\"reverse\"
        android:animation=\"@anim/slide_right\" />
因此,您可以使用XML创建序列并将其放入Android项目资源的“ /res/anim/some_file.xml”中。您可以在此处获得有关如何创建此XML文件的更多详细信息。 您也可以通过代码执行以下操作:
  AnimationSet set = new AnimationSet(true);

  Animation animation = new AlphaAnimation(0.0f, 1.0f);
  animation.setDuration(100);
  set.addAnimation(animation);

  animation = new TranslateAnimation(
      Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
      Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f
  );
  animation.setDuration(500);
  set.addAnimation(animation);

  LayoutAnimationController controller =
      new LayoutAnimationController(set, 0.25f);
  button.setLayoutAnimation(controller);
然后:
public static Animation runSlideAnimationOn(Activity ctx, View target) {
  Animation animation = AnimationUtils.loadAnimation(ctx,
                                                     android.R.anim.slide_right);
  target.startAnimation(animation);
  return animation;
}
    

要回复问题请先登录注册