【问题标题】:android expandableListView animate slide up?android expandableListView 动画向上滑动?
【发布时间】:2012-05-08 02:50:43
【问题描述】:

当我单击 groupItem 时,我想在 expandablelistview 上为向下滑动和向上滑动设置动画。然后我完成了向下滑动。

public class ExpandAnimation extends Animation {
private static final String TAG = "ExpandAnimation";
private View mAnimatedView;
private LayoutParams mViewLayoutParams;
private int mMarginStart, mMarginEnd;
private boolean mIsVisibleAfter = false;
private boolean mWasEndedAlready = false;

/**
 * Initialize the animation
 * @param view The layout we want to animate
 * @param duration The duration of the animation, in ms
 */
public ExpandAnimation(View view, int duration) {

    setDuration(duration);
    mAnimatedView = view;
    mViewLayoutParams = (LayoutParams) view.getLayoutParams();
    // if the bottom margin is 0,
    // then after the animation will end it'll be negative, and invisible.
    mIsVisibleAfter = (mViewLayoutParams.bottomMargin == 0);

    mMarginStart = mViewLayoutParams.bottomMargin;
    Log.i(TAG, "mMarginStart:>>>>>>>"+mMarginStart);
    mMarginEnd = (mMarginStart == 0 ? (0- view.getHeight()) : 0);
    Log.i(TAG, "mMarginEnd:>>>>>>>"+mMarginEnd);

    view.setVisibility(View.VISIBLE);
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    super.applyTransformation(interpolatedTime, t);
    Log.i(TAG, "applyTransformation-->"+interpolatedTime);
    if (interpolatedTime < 1.0f) {

        // Calculating the new bottom margin, and setting it
        mViewLayoutParams.bottomMargin = mMarginStart
                + (int) ((mMarginEnd - mMarginStart) * interpolatedTime);

        // Invalidating the layout, making us seeing the changes we made
        mAnimatedView.requestLayout();

    // Making sure we didn't run the ending before (it happens!)
    } else if (!mWasEndedAlready) {
        mViewLayoutParams.bottomMargin = mMarginEnd;
        mAnimatedView.requestLayout();

        if (mIsVisibleAfter) {
            mAnimatedView.setVisibility(View.GONE);

        }
        mWasEndedAlready = true;
    }
}

}

public View getChildView(int groupPosition, int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {
    Log.i(TAG, "getChildView");
    @SuppressWarnings("unchecked")
    String text = ((Map<String, String>) getChild(groupPosition,
            childPosition)).get("child");
    if (convertView == null) {
        LayoutInflater layoutInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        convertView = layoutInflater.inflate(R.layout.child, null);

    }
    View toolbar = convertView.findViewById(R.id.toolbar);
    setAnimationView(toolbar);
    ((LinearLayout.LayoutParams) toolbar.getLayoutParams()).bottomMargin = -75;
    toolbar.setVisibility(View.GONE);
    ExpandAnimation expandAni = new ExpandAnimation(toolbar, 1000);
    toolbar.startAnimation(expandAni);
    TextView tv = (TextView) convertView.findViewById(R.id.childTo);
    tv.setText(text);

    return convertView;
}

但是当我点击 groupItem 折叠组时,它并没有调用 getChildView() 方法。那么如何调用 getChildView() 并让它向上滑动呢?

【问题讨论】:

  • mViewLayoutParams 显示空值,但视图中有一个值
  • getChildView() 是在 group 的孩子上调用的,所以只有在展开时才会调用...

标签: android-animation expandablelistview


【解决方案1】:

如果你想调用(或@Override)getChildView,我相信你想扩展 BaseExpandableListAdapter。

http://developer.android.com/reference/android/widget/BaseExpandableListAdapter.html

【讨论】:

    猜你喜欢
    • 2012-02-05
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    相关资源
    最近更新 更多