Java android布局上的折叠动画
我遇到了这个问题,我有一个类似手风琴的活动,按钮根据其状态展开或折叠布局,然后问题出现在动画中,展开动画非常完美,但折叠时,它通过父按钮上方的布局,我想相对于布局折叠它 对不起,我的英语不好,代码如下:Java android布局上的折叠动画,java,android,eclipse,animation,Java,Android,Eclipse,Animation,我遇到了这个问题,我有一个类似手风琴的活动,按钮根据其状态展开或折叠布局,然后问题出现在动画中,展开动画非常完美,但折叠时,它通过父按钮上方的布局,我想相对于布局折叠它 对不起,我的英语不好,代码如下: public class Animations extends Animation { /** * Initializes expand collapse animation, has two types, collapse (1) and expand (0). * @param vie
public class Animations extends Animation {
/**
* Initializes expand collapse animation, has two types, collapse (1) and expand (0).
* @param view The view to animate
* @param duration
* @param type The type of animation: 0 will expand from gone and 0 size to visible and layout size defined in xml.
* 1 will collapse view and set to gone
*/
public AnimationSet AnimationSet;
public Animations(String type) {
if (type == "Expand")
AnimationSet = ExpandAnimation();
if (type == "Collapse")
AnimationSet = CollapseAnimation();
}
public AnimationSet ExpandAnimation() {
AnimationSet _set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(250);
_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(150);
_set.addAnimation(animation);
return _set;
}
public AnimationSet CollapseAnimation() {
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(1.0f, 1.0f);
animation.setDuration(250);
set.addAnimation(animation);
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f
);
animation.setDuration(250);
set.addAnimation(animation);
return set;
}
}为什么不使用反转内极器来反转已经运行得如此完美的扩展动画
public class ReverseInterpolator implements Interpolator {
public float getInterpolation(float paramFloat) {
return Math.abs(paramFloat -1f);
}
}
在_set变量上:
_set.setInterpolator(new ReverseInterpolator());
或
我还要强调一些你做得不正确的事情:
将.equals用于比较的字符串,而不是==。这是错误的->如果类型==展开。此外,请正确命名方法和变量,例如
public AnimationSet AnimationSet; //poor
public AnimationSet expandAnim; //better
public AnimationSet ExpandAnimation() { //poor
public AnimationSet expand() { //better
为什么不使用反转内极器反转已经非常完美的扩展动画
public class ReverseInterpolator implements Interpolator {
public float getInterpolation(float paramFloat) {
return Math.abs(paramFloat -1f);
}
}
在_set变量上:
_set.setInterpolator(new ReverseInterpolator());
或
我还要强调一些你做得不正确的事情:
将.equals用于比较的字符串,而不是==。这是错误的->如果类型==展开。此外,请正确命名方法和变量,例如
public AnimationSet AnimationSet; //poor
public AnimationSet expandAnim; //better
public AnimationSet ExpandAnimation() { //poor
public AnimationSet expand() { //better
只需将属性添加到最顶部的布局。它具有类似淡出的默认动画
android:animateLayoutChanges="true"
然后设置可折叠布局的可见性消失/可见。只需向最顶部的布局添加一个属性即可。它具有类似淡出的默认动画
android:animateLayoutChanges="true"
然后设置可折叠布局的可见性/可见