在View.layout(l,t,r,b)之后Android不重绘 [英] Android Not Redrawing after View.layout(l,t,r,b)
问题描述
我正在尝试使用ImageButton.layout(l,t,r,b)在布局的特定位置放置多个图像。安排好它们之后,我想在每个ImageButton上执行一个动画。问题在于,动画会在屏幕上ImageButtons的位置更改之前开始,从而导致动画看起来不正确。
I am attempting to place several images at specific points on my layout using ImageButton.layout(l,t,r,b). After they are arranged, I would like to execute an animation on each ImageButton. The trouble is, the animation starts before the positions of the ImageButtons has changed on the screen, causing the animation to look wrong.
如何解决此问题?这是一些代码...
How can I fix this? Here is a bit of code...
private void arrangeButtons()
{
int temp = 0;
for(ImageButton imageButtonButton :imageButtonList) {
imageButtonButton.setCurrentPositionIndex(temp);
int l = PositionsLeft[temp];
int t = PositionsTop[temp];
int r = PositionsRight[temp];
int b = positionsBottom[temp];
currentButton.layout(l,t,r,b);
temp++;
}
ViewGroup vg = (ViewGroup)findViewById(R.id.imageListFrame);
vg.invalidate();
vg.refreshDrawableState();
}
public static void rotateButtons() {
for(ImageButton imageButton : imageButtonList) {
RotateAnimation rotation = new RotateAnimation(0, 45, 25, 25);
imageButton.setAnimation(rotation);
imageButton.startAnimation(rotations);
}
}
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
arrangeButtons();
rotateButtons();
}
有什么想法吗?谢谢!
推荐答案
尝试在<$ c $之后调用 requestLayout()
c> currentButton.layout(l,t,r,b); 或更好的方法是使用 setLayoutParams
来更改视图在屏幕上的位置
Try calling requestLayout()
after currentButton.layout(l,t,r,b);
or better yet use setLayoutParams
to change the position of the view on the screen.
这篇关于在View.layout(l,t,r,b)之后Android不重绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!