我在试着创建一个独臂的强盗应用。我已经创建了一个动画xml文件来遍历多个图像。单击按钮时,动画将停止。
我的问题是如何将一个动画停止的图片与另一个动画的图片进行比较?到目前为止,我已经尝试了这样的东西:
if(wheel1.getBackground().getConstantState().equals(wheel2.getBackground().getConstantState())) matches++;任何帮助都是非常感谢的。
发布于 2017-02-16 12:45:46
View不应该维护应用程序逻辑,而应该由控制器(托管Activity或Fragment)维护。
也就是说,要实现您想要的功能,请使用View.setTag()将每个View的逻辑描述应用于它。然后当停止动画时,循环你所有的Views并获取它们在屏幕上的位置,让Views在你的bandit机器的每一列中最明显,并比较它们的标签(View.getTag())
例如,如果项目是垂直动画,请使用下面的方法来确定土匪停止的位置。
//the area where to compare views
int BOUND_TOP, BOUNT_DOWN;
//your content view
ViewGroup rootLayout;
//method to get information about what is visible
public List<Object> getVisibleViewTags() {
    List<Object> list = new LinkedList<>();
    int count = rootLayout.getChildCount(); 
    for (int pos = 0; pos < count; pos++) {
        View child = rootLayout.getChildAt(pos);
        float translationY = child.getTranslationY();
        if (translationY > BOUND_TOP && translationY < BOUND_DOWN) {
            list.add(child.getTag());
        }
    }
    return list;
}现在,您只需要将有关视图的信息作为标记附加到它。示例:
view.setTag("view_apples");或
view.setTag("view_bananas");https://stackoverflow.com/questions/42262811
复制相似问题