我目前正在使用九个旧 Android 来为 RelativeLayout 设置动画,例如滑块菜单,它从顶部向下滑动。我尝试了很多方法,有人可以提出建议吗?
这是动画代码:
private OnClickListener slideClick = new OnClickListener(){
@Override
public void onClick(View v) {
slideGroups.bringToFront();
if(!mPulledDown) {
ObjectAnimator oa = ObjectAnimator.ofFloat(slideGroups, "translationY", slideGroups.getHeight()-80);
oa.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator arg0) {}
@Override
public void onAnimationRepeat(Animator arg0) {}
@Override
public void onAnimationEnd(Animator arg0) {
arrow.setImageResource(R.drawable.arrowup);
if(Application.getAndroidAPILevel() < 11) {
// only if pre 3.0 (api level 11)
Toast.makeText(FriendsActivity.this, String.format("api level %s",
Application.getAndroidAPILevel()), Toast.LENGTH_SHORT).show();
//RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) slideGroups.getLayoutParams();
// clear animation to prevent flicker
slideGroups.clearAnimation();
// set new "real" position of wrapper
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, slideGroups.getWidth());
//lp.addRule(RelativeLayout.BELOW, R.id.branchFinderIncludeHeader);
slideGroups.setLayoutParams(lp);
}
}
@Override
public void onAnimationCancel(Animator arg0) {}
});
oa.start();
}
else
{
ObjectAnimator oa = ObjectAnimator.ofFloat(slideGroups, "translationY", 0);
oa.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator arg0) {}
@Override
public void onAnimationRepeat(Animator arg0) {}
@Override
public void onAnimationEnd(Animator arg0) {
arrow.setImageResource(R.drawable.arrowdown);
if(Application.getAndroidAPILevel() < 11) {
// only if pre 3.0 (api level 11)
Toast.makeText(FriendsActivity.this, String.format("api level %s",
Application.getAndroidAPILevel()), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onAnimationCancel(Animator arg0) {}
});
oa.start();
}
mPulledDown = !mPulledDown;
}
};
我只需要一些可以与 sdk 4 级及更高版本一起工作的东西。目前,触摸/点击会在展开时将该事件传递到滑块下方的列表。如果需要任何其他信息,请告诉我。slideGroups 是相对布局。箭头是一个图像视图。groupsButton 是一个带有文本和图像按钮的 LinearLayout。groupsButton 应该是可点击的;这就是扩展并且应该折叠它。
提前致谢。