我想用 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;
}
再次感谢。
最佳答案
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 更改为其他名称。混合实例名称和其他类的名称是非常糟糕的风格。
好的代码是 here .
关于java - Android 在循环中移动图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45037496/