如何在这个动画之后 rest/initial-state 一个视图?

How to rest/initial-state a view after this animation?

正如标题所说,我需要将 TextViewImageView 和其他视图重置为初始状态。例如,在触摸该特定视图后,会播放一个动画,并且它的动画会(视觉上)销毁该视图。

现在我需要重新绘制它。希望你明白了。我还使用了 https://github.com/tyrantgit/ExplosionField 的 ExplosionField 效果。我有 运行 代码并且可以正常工作。

代码如下:

private ExplosionField mExplosionField;
private TextView tv_1;

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

    tv_1 = (TextView)findViewById(R.id.mytext_xml);
    mExplosionField = ExplosionField.attach2Window(this);
    addListener(findViewById(R.id.root));

}

private void addListener(View root) {
    // TODO Auto-generated method stub
    if (root instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) root;
        for (int i = 0; i < parent.getChildCount(); i++) {
            addListener(parent.getChildAt(i));
        }
    } else {
        root.setClickable(true);
        root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mExplosionField.explode(v);
                v.setOnClickListener(null);
            }
        });
    }
}

现在,按下 "action_reset" 它必须从头开始绘制那个 TextView。

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_reset) {
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
}

我知道需要的代码在 "if (id == R.id.action_reset)" 之后,但我已经尝试了几种通过互联网找到的方法,但是 none成功了。

注: 请转到 https://github.com/tyrantgit/ExplosionField 并考虑示例。我需要知道如何通过按下按钮重新绘制。

我仍然不明白你所说的 destroy that view 是什么意思。重置视图取决于您所做的更改。取决于您需要撤消更改。如果您已将可见性设置为 Gone,那么现在您需要将其设置为 Visible

所以我检查了代码。将以下内容添加到您的代码中。事情应该有效:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_reset) {
        View root = findViewById(R.id.root);
        reset(root);
        addListener(root);
        mExplosionField.clear();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

private void reset(View root) {
    if (root instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) root;
        for (int i = 0; i < parent.getChildCount(); i++) {
            reset(parent.getChildAt(i));
        }
    } else {
        root.setScaleX(1);
        root.setScaleY(1);
        root.setAlpha(1);
    }
}

有关详细信息,请参阅此处的完整代码:https://github.com/tyrantgit/ExplosionField/blob/master/app/src/main/java/tyrantgit/sample/MainActivity.java