1

在 hello android book 中有一个数独解决方案。我想在最后创建一条消息,显示一个表示祝贺的对话框。我有一个方法来检查是否还有任何空方格,我在另一个方法中调用它来检查最后一个输入是否是方格的有效条目

/****** Check to see if the game is complete **/
public boolean isSolved() {
    for (int element : puzzle) {
        if (element == 0)
            return false;
    }
    return true;
}

/** Change the tile only if it's a valid move */
protected boolean setTileIfValid(int x, int y, int value) {
    int tiles[] = getUsedTiles(x, y);
    if (value != 0) {
        for (int tile : tiles) {
            if (tile == value)
                return false;
        }
    }
    setTile(x, y, value);
    calculateUsedTiles();
    //check if the game is complete after each valid move
            if (isSolved() == true) { 
                Intent i = new Intent(this, Congratulations.class); 
                startActivity(i);} 
                else
                {
                    return false;
                }
    return true;
}

出于某种原因,当我在游戏完成之前进入一个图块时,整个屏幕会左右晃动。这在我进入游戏检查之前没有这样做。为什么以及在哪里这样做?

Congratulatons.xml <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dip" > <TextView android:id="@+id/about_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/congratulations_text" /> </ScrollView> Congratulations.java

package com.example.sudoku;
import android.app.Activity;
import android.os.Bundle;
public class Congratulations extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.congratulations);
}
}
4

1 回答 1

1

好像有一些动画,负责摇动屏幕。它可能会附加到祝贺活动中。

我认为您需要为此方法搜索代码(尤其是祝贺活动):

startAnimation(AnimationUtils.loadAnimation(context,R.anim.shake));

Or it could be a theme (also custom theme) responsible for the animation in the activity tag of the AndroidManifest.xml

Maybe it's not the Congratulations Activity at all. It's probably the code part which is called, when the Sudoku was not solved yet.

于 2012-08-31T02:06:31.210 回答