我想将多个 ImageView 的 ScaleX 和 ScaleY 设置为相同的值。 是否可以循环执行?
for(int i=1;i<=9;i++){
String img = "imageview" + i;
(imageview + i).setScaleX(x);
}
// x is the variable
最佳答案
我还没有测试过,但这应该有效
<小时/>您可以为每个 ImageView
设置一个标签,确保递增每个标签,例如:
//first ImageView
android:tag="@string/one" //one = 1
//second ImageView
android:tag="@string/two" //two = 2
然后在 for 循环中:
for(int i=1;i<=9;i++){
ImageView img = findViewWithTag(String.valueOf(i));
img.setScaleX(x);
}
但我不会推荐这个。相反,只需为每个单独设置 setScaleX(x)
即可。代码并不多。
关于java - 是否有可能在循环中设置多个 ImageView 的比例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56613032/