/ / Androidループ内の画像の移動-Java、Android、forループ

Androidでの画像の移動 - java、android、for-loop

Forループで画像を移動するか、そのようなことを行うための情報を見つけたい

ここに私のcontent_main.xmlの一部があります

ffImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView" android:src="@drawable/pic" android:layout_marginLeft="41dp" android:layout_marginStart="41dp" android:layout_marginTop="139dp" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" />

だからどうすれば

int A;
A = 41;
for ( int i = 0; i < 50 ; i++) {
android:layout_marginLeft=A;
A = A +1;
}

よろしくお願いします。

回答:

回答№1は0
ImageView image;
RelativeLayout layout = (RelativeLayout)findViewById(R.id.imageView);
ImageView image= new ImageView (this);
image.setImageResource(R.drawable.YOUR_IMAGE);
layout.addView(image);

int A;
A = 41;
for ( int i = 0; i < 50 ; i++) {
image.setX(A);
A+=step;
layout.invalidate();
}

ただし、レイアウトの名前をimageViewから別の名前に変更する方が適切です。インスタンスの名前と他のクラスの名前を混ぜることは非常に悪いスタイルです。

良いコードは ここに.