【发布时间】:2014-05-21 16:07:51
【问题描述】:
我在java中为listview实现了一个动画,就像当你点击一个列表项时,一个视图会向下滑动,两个按钮在点击时执行单独的选项,再次点击它会向上滑动,使列表项看起来很正常(它确实也会上下推动其他项目)所以这个动画的持续时间已设置为 500,以便它顺利进行。
但是,问题是第一次单击列表项显示动画太快(第一次单击后再次平滑) 这对所有列表项都是一样的。
我尝试了很多来解决这个问题。我让你看看我的动画课和我的 onitemclicklistener 。
(问题 2 :- 第一个问题更重要,但如果你也能解决这个问题,那就继续吧) 还有一个问题,对不起,但忘了动画一秒钟,当视图向下滑动并且您向下滚动到无法看到列表项时,现在当您返回时列表项不再展开(滑出) ,这是因为视图的回收,但我怎么能绕过这个呢
动画类:-
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.LinearLayout;
public ExpandCollapseAnimation(View view, int type) {
setDuration(500);
mAnimatedView = view;
mEndHeight = mAnimatedView.getMeasuredHeight();
mLayoutParams = ((LinearLayout.LayoutParams) view.getLayoutParams());
mType = type;
if(mType == EXPAND) {
setDuration(500);
mLayoutParams.bottomMargin = -mEndHeight;
} else {
setDuration(500);
mLayoutParams.bottomMargin = 0;
}
view.setVisibility(View.VISIBLE);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
setDuration(500);
super.applyTransformation(interpolatedTime, t);
if (interpolatedTime < 1.0f) {
if(mType == EXPAND) {
setDuration(500);
mLayoutParams.bottomMargin = -mEndHeight + (int) (mEndHeight * interpolatedTime);
} else {
setDuration(500);
mLayoutParams.bottomMargin = - (int) (mEndHeight * interpolatedTime);
}
Log.d("ExpandCollapseAnimation", "anim height " + mLayoutParams.bottomMargin);
mAnimatedView.requestLayout();
} else {
if(mType == EXPAND) {
setDuration(500);
mLayoutParams.bottomMargin = 0;
mAnimatedView.requestLayout();
} else {
setDuration(500);
mLayoutParams.bottomMargin = -mEndHeight;
mAnimatedView.setVisibility(View.GONE);
mAnimatedView.requestLayout();
}
}
}
}
实施:-
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
View toolbar = view.findViewById(R.id.toolbar);
if(toolbar.getVisibility() == View.GONE){
ExpandCollapseAnimation expandAni = new ExpandCollapseAnimation(toolbar, 0);
toolbar.startAnimation(expandAni);
}else if(toolbar.getVisibility() == View.VISIBLE){
ExpandCollapseAnimation expandAmi = new ExpandCollapseAnimation(toolbar, 1);
toolbar.startAnimation(expandAmi);
}
}
});
【问题讨论】:
标签: android listview button slider views