2

誰かが私がこれをするのを手伝ってくれますか?私はAndroidアプリを構築しようとしていますが、その間に立ち往生しています。

次のコードを使用して画像を移動しました。ivはImageViewオブジェクトです

moveImage = new TranslateAnimation( 0, xDest, 0, -yDest);
moveImage.setDuration(1000);
moveImage.setFillAfter( true );
iv.startAnimation(moveImage);

コード:

public class gameLogic extends Activity 
{
ImageView image;
TranslateAnimation moveImage;

public void onCreate(Bundle icicle) 
{
    super.onCreate(icicle);
    setContentView(R.layout.game_logic);
    imageMoveRandom(imageList(image,0));
}

ImageView imageList(ImageView v,int i)
{
    v = (ImageView) findViewById(R.id.rabbit);
    int imgId;
    int j = i;

    TypedArray imgs = getResources().obtainTypedArray(R.array.random_imgs);
    //get resourceid by index

    imgId = imgs.getResourceId(j, 0);
    // or set you ImageView's resource to the id
    v.setBackgroundResource(imgId);

    return v;

}

void imageMoveRandom(ImageView iv)throws NotFoundException
{
    DisplayMetrics dm = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics( dm );

    int xDest = dm.widthPixels/2;
    int yDest = dm.heightPixels/2;

//      Toast.makeText(gameLogic.this, dm.widthPixels, Toast.LENGTH_SHORT).show();
        //      Toast.makeText(this, dm.heightPixels, 2000).show();


        moveImage = new TranslateAnimation( 0, xDest, 0, -yDest);
        moveImage.setDuration(1000);
        moveImage.setFillAfter( true );
        iv.startAnimation(moveImage);
        //moveImage.reset();
    }
}

上記は完全なコードではありませんが、参照に役立つ可能性のある部分です。

しかし、私は画像をランダムな場所に、しかしアンドロイドディスプレイ内で継続的に移動したいと思います。誰でも解決策を提案できますか?

前もって感謝します :)

4

1 に答える 1

-3
 class BitmapView extends View
 {
   changingX=10;
   changingY=10;
   public BitmapView(Context context) {
        super(context);
   }
   @Override
   public void onDraw(Canvas canvas) {
   Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.yourImageName);
    canvas.drawColor(Color.BLACK);
    canvas.drawBitmap(bmp, changingX,changingY, null);
    changingX=changingX+5;
    changingY=changingY+10;
    invalidate();
   }
}

これを試して

于 2012-12-04T07:11:13.930 に答える