点击查看orhu
我从下到上安排了ulayout,点击backgroundview
我通过从上到下制作动画使其无法看到。但问题是这两个动画只发生在我第一次点击orbhu
。然后没有动画发生,除非我重新打开活动,否则视图会变得可见并且不会显示动画。为什么这样,我该如何解决?
slide_down
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0%p" android:toYDelta="100%p" android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator"
android:duration="500" />
</set>
slide_up
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="100%p" android:toYDelta="0%p"
android:fillAfter="true"
android:duration="500"/>
</set>
代码
slideDown = AnimationUtils.loadAnimation(mContext,
R.anim.slide_down);
slideUp = AnimationUtils.loadAnimation(mContext,
R.anim.slide_up);
orbhu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ulayout.setAnimation(slideUp);
ulayout.setVisibility(View.VISIBLE);
backgroundview.setVisibility(View.VISIBLE);
}
});
backgroundview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ulayout.setAnimation(slideDown);
backgroundview.setVisibility(View.GONE);
ulayout.setVisibility(View.GONE);
}
});
答案 0 :(得分:2)
请尝试使用以下代码
slideDown = AnimationUtils.loadAnimation(mContext,
R.anim.slide_down);
slideUp = AnimationUtils.loadAnimation(mContext,
R.anim.slide_up);
orbhu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ulayout.startAnimation(slideUp);
ulayout.setVisibility(View.VISIBLE);
backgroundview.setVisibility(View.VISIBLE);
}
});
backgroundview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ulayout.startAnimation(slideDown);
backgroundview.setVisibility(View.GONE);
ulayout.setVisibility(View.GONE);
}
});