0

私はすでにこれをコード化して動作させていますが、これに対するより良い解決策があるかどうか疑問に思っています.

現在動作する私のコードは次のとおりです。

    _index = 1;
    _timer = new Timer();
    _timer.schedule(new TickClass(), 1000, 1000);

public class TickClass extends TimerTask
{
    private int columnIndex;

    @Override
    public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (_index == 1) {
                        columnIndex = cursor.getColumnIndex(MySQLiteHelper.COLUMN_IMAGE_2);
                        _index = 2;
                    }
                    else {
                        columnIndex = cursor.getColumnIndex(MySQLiteHelper.COLUMN_IMAGE_1);
                        _index = 1; 
                    }   

                    String image_1 = cursor.getString(columnIndex);
                    image_1 = image_1.replace(".png", "");
                    int resourceId = getResources().getIdentifier(getPackageName() + ":drawable/" + image_1, null, null);
                    image_1_view.setImageDrawable(getResources().getDrawable(resourceId));
                }
            });
        }
}

ご覧のとおり、2 つのドローアブル名は SQLite データベース テーブルから取得されています。

4

1 に答える 1

0

AnimationDrawable の使用は、複数の画像からアニメーションを作成する「公式」の方法です。

http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html http://developer.android.com/guide/topics/graphics/drawable-animation.html

于 2013-06-06T05:49:19.990 に答える