【问题标题】:Custom ListView with animated visibility toggle具有动画可见性切换的自定义 ListView
【发布时间】:2013-11-05 13:31:02
【问题描述】:

我有一个自定义列表视图,里面有很多文本。我希望当我点击列表视图时,其他文本会出现在点击的行下方。我设法做到这一点,将 TextView 设置为 GONE custom_row.xml,然后在 ClickListener 中将其设置为 VISIBLE.. 但这太小故障了,所以我想制作一个切换动画,如 JQUERY 的盲人表演......

如何在 Android 中使用动画制作这个?

【问题讨论】:

    标签: android listview android-listview android-animation


    【解决方案1】:

    您可以创建自己的动画并更改项目的高度,例如:

    public class ExpandAnimation extends Animation {
    ...
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
           super.applyTransformation(interpolatedTime, t);
            if (interpolatedTime < 1.0f) {
                viewLayoutParams.height = heightStart + 
                        (int) (( heightEnd - heightStart) * interpolatedTime);
                animatedView.requestLayout();
            }
        }
    }
    

    并在项目被点击时设置此动画。

    【讨论】:

      【解决方案2】:

      使用ValueAnimator 将 ListView 的高度从 0 更改为最终高度。

      你可以找到一个很好的例子in this tutorial

      代码如下:

      ValueAnimator animator = ValueAnimator.ofInt(intialHeight, finalHeight);    
      animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator v) {
              int value = (Integer) v.getAnimatedValue(); // get the most recent value calculated by the ValueAnimator 
              ViewGroup.LayoutParams lp = yourLayout.getLayoutParams(); // get the height of your ListView
              lp.height = value; //change the height
              mLinearLayout.setLayoutParams(layoutParams); //update it to the view
          }   
      animator.start(); //start the animation
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-05-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多