gpt4 book ai didi

android - RemoveViews 不工作

转载 作者:太空宇宙 更新时间:2023-11-03 10:20:23 24 4
gpt4 key购买 nike

我有以下代码,一切正常。除了删除 View 不起作用。我的代码有什么问题?删除 View 在动画中不起作用吗?

在我的oncreate上

  @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_edit_profile);

mWinManager = (WindowManager) ManageProfileActivity.this
.getSystemService(Context.WINDOW_SERVICE);

final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT);

params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;

mParentView = new FrameLayout(ManageProfileActivity.this);
mParentViewlayout = new FrameLayout.LayoutParams(100, 100);

mWinManager.addView(mParentView, params);

在我的gridView Item点击

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

ImageView original = (ImageView) view.findViewById(R.id.avatar_imageview);
final ImageView img = new ImageView(ManageProfileActivity.this);
img.setVisibility(View.VISIBLE);


img.setImageDrawable(original.getDrawable());
mParentView.addView(img, mParentViewlayout);

int[] img_coordinates = new int[2];
mGroupAvatarImageView.getLocationOnScreen(img_coordinates);
float mX = (float) ((img_coordinates[0]));
float mY = (float) ((img_coordinates[1]));

TranslateAnimation anim = new TranslateAnimation(x, mX, y, mY);
anim.setDuration(300);
anim.setAnimationListener(new TranslateAnimation.AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
}

@Override
public void onAnimationRepeat(Animation animation) {
}

@Override
public void onAnimationEnd(Animation animation) {
//THIS IS NOT WORKING
mParentView.removeView(img);
mParentView.invalidate();
}
});

img.startAnimation(anim);

最佳答案

您不能在 onAnimationEnd 中更改 View 层次结构。解决方法是推迟删除 subview 。尝试像这样使用:

 @Override
public void onAnimationEnd(Animation animation) {
mParentView.post(new Runnable() {

@Override
public void run() {
mParentView.removeView(img);
}
});
}

关于android - RemoveViews 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24160544/

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