gpt4 book ai didi

android - 如何定位 View 以便点击在动画后起作用

转载 作者:行者123 更新时间:2023-11-29 21:56:51 24 4
gpt4 key购买 nike

我目前正在使用九个旧机器人为 RelativeLayout 制作动画,就像一个从顶部向下滑动的 slider 菜单。我尝试了很多方法,有人可以提出建议吗?

这是动画代码:

  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 和更新版本。目前,触摸/点击会在展开时将该事件传递给 slider 下方的列表。如果需要任何其他信息,请告诉我。 slideGroups 是 RelativeLayout。箭头是 ImageView 。 groupsButton 是带有文本和图像按钮的 LinearLayout。 groupsButton 应该是可点击的;这就是扩展并应该折叠它的东西。

提前致谢。

最佳答案

一些人通过使用解决方案编辑我的问题做出了贡献。我想赞扬他们,但不能赞成编辑。对于后代,这是适合我的解决方案。

int originalMarginLeft = 0;
int originalMarginTop = 0;
int originalMarginRight = 0;
int originalMarginBottom = 0;
int originalLeft = 0;
int originalTop = 0;
int originalRight = 0;
int originalBottom = 0;
int originalX = 0;
int originalY = 0;
int originalHeight = 0;

private OnClickListener slideClick = new OnClickListener(){
@Override
public void onClick(View v) {
slideGroups.bringToFront();

if(originalMarginLeft == 0) {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) slideGroups.getLayoutParams();
originalMarginLeft = params.leftMargin;
originalMarginTop = params.topMargin;
originalMarginRight = params.rightMargin;
originalMarginBottom = params.bottomMargin;
originalLeft = slideGroups.getLeft();
originalTop = slideGroups.getTop();
originalRight = slideGroups.getRight();
originalBottom = slideGroups.getBottom();
originalHeight = params.height;
}

if(!mPulledDown) {
ObjectAnimator oa = ObjectAnimator.ofFloat(slideGroups, "translationY", originalHeight);
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) {

slideGroups.clearAnimation();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(slideGroups.getWidth(), slideGroups.getHeight());
lp.leftMargin = originalMarginLeft;
lp.rightMargin = originalMarginRight;
slideGroups.setLayoutParams(lp);

}
}

@Override
public void onAnimationCancel(Animator arg0) {}
});
oa.start();
}
else
{
ObjectAnimator oa = ObjectAnimator.ofFloat(slideGroups, "translationY", -originalHeight+60);
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) {

slideGroups.clearAnimation();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(slideGroups.getWidth(), slideGroups.getHeight());
lp.leftMargin = originalMarginLeft;
lp.rightMargin = originalMarginRight;
lp.topMargin = originalMarginTop;
lp.bottomMargin = originalMarginBottom;
slideGroups.setLayoutParams(lp);
}
}

@Override
public void onAnimationCancel(Animator arg0) {}
});
oa.start();
}

mPulledDown = !mPulledDown;
}
};

关于android - 如何定位 View 以便点击在动画后起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13022387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com