Android在查看布局(l、t、r、b)后未重新绘制
我正在尝试使用ImageButton.layout(l、t、r、b)在布局上的特定点放置多个图像。安排好之后,我想在每个ImageButton上执行一个动画。问题是,动画在屏幕上ImageButtons的位置更改之前启动,导致动画看起来出错 我怎样才能解决这个问题?这里有一些代码Android在查看布局(l、t、r、b)后未重新绘制,android,animation,view,Android,Animation,View,我正在尝试使用ImageButton.layout(l、t、r、b)在布局上的特定点放置多个图像。安排好之后,我想在每个ImageButton上执行一个动画。问题是,动画在屏幕上ImageButtons的位置更改之前启动,导致动画看起来出错 我怎样才能解决这个问题?这里有一些代码 private void arrangeButtons() { int temp = 0; for(ImageButton imageButtonButton :imageButtonList) {
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();
}
有什么想法吗?谢谢 尝试在
currentButton.layout(l、t、r、b)之后调用requestLayout()
或更好的方法是使用setLayoutParams
更改视图在屏幕上的位置。谢谢您的帮助。我现在正在使用setLayoutParams,但是我已经发现了问题的根源。现在我删除了动画,发现即使使用setLayoutParams,topMargin rightMargin等都会在创建完成时重置为(0,0,0,42)。为什么会这样?!非常感谢您的任何帮助,哈哈,我很困惑……也许您正在用xml设置边距?另外,您对super.onCreate()的调用在哪里?我发布的代码被简化了[我有super调用]。我认为可能是xml覆盖了这个位置,所以我扩展了LinearLayout,覆盖了onFinishInflate,并从那里调用了arrangeButtons,遇到了同样的问题。这是我发现的问题,哈哈。。。