0
在android中,我如何添加動畫到視圖時,其添加到mainview,例如慢慢增長和佔領主視圖。我認爲它可能,但從哪裏開始,我需要它爲我的ListView展開其他視圖時刪除。如何添加動畫到一個視圖,而它被添加到主視圖
謝謝
在android中,我如何添加動畫到視圖時,其添加到mainview,例如慢慢增長和佔領主視圖。我認爲它可能,但從哪裏開始,我需要它爲我的ListView展開其他視圖時刪除。如何添加動畫到一個視圖,而它被添加到主視圖
謝謝
我有一個演示。它上下移動非常順利的時候添加或隱藏視圖
public class ExpandAnimation extends Animation {
private View mAnimatedView;
private LayoutParams mViewLayoutParams;
private int mMarginStart, mMarginEnd;
private boolean mIsVisibleAfter = false;
private boolean mWasEndedAlready = false;
ImageButton mImageButton;
/**
* 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, ImageButton button) {
this.mImageButton = button;
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;
mMarginEnd = (mMarginStart == 0 ? (0- view.getHeight()) : 0);
view.setVisibility(View.VISIBLE);
button.setImageResource(R.drawable.bar_down);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
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);
mImageButton.setImageResource(R.drawable.bar_up);
}
mWasEndedAlready = true;
}
}
}
btnShowBookmarkBar.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
animation = new ExpandAnimation(bookmarkControlView,
CommConstant.DEFAULT_SHOW_UP_TIME, btnShowBookmarkBar);
btnShowBookmarkBar.startAnimation(animation);
}
});
您可以介紹一下你的問題嗎? – Ashishsingh