【问题标题】:Animate different view in a LinearLayout on Android在 Android 上的 LinearLayout 中为不同的视图设置动画
【发布时间】:2013-08-05 15:44:44
【问题描述】:

我有一个带有一些元素(A、B 和 C)的 LinearLayout:

-------
|  A  |
+-----+
|  B  |
+-----+
|  C  |
-------

而且一开始B是GONE(View.GONE),但是当用户按下A时,B会显示动画:

public static LayoutAnimationController getLayoutAnimation_slideDownFromTop(Context ctx) {

      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(300);
      set.addAnimation(animation);

      LayoutAnimationController controller = new LayoutAnimationController(set, 0f);
      return controller;
}

视图 B 是动画属性,但视图 C 只是跳到最后,我想知道是否有一种标准方法可以使 B 和 C 动画同时向下滑动

【问题讨论】:

    标签: android android-linearlayout android-animation


    【解决方案1】:

    你可以使用 android:animateLayoutChanges 属性:

    <LinearLayout
        android:animateLayoutChanges="true"
        ...
    />
    

    这里是the link,提供更多信息。

    【讨论】:

    • 这只适用于 API 级别 11,我需要它用于 API 级别 8
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    • 2016-11-01
    • 1970-01-01
    相关资源
    最近更新 更多