我有这个GUI:
线性布局
-TableLayout heading
-ViewFlipper flipper
- TableLayout1
- TableLayout2
- TableLayout3
... (dynamicly added)
我在 vf.onLayout(..) 中更改了 t1 的宽度,但我无法重新绘制它....请帮忙 :/这是代码:
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
Log.i(TAG, "flipper onLayout");
int idx = this.getDisplayedChild();
Log.i(TAG, "flipper displayed child is: " + idx);
this.heading.cols_widths = some_cols_widths;
this.heading.resize_cols();
LinearLayout lay = (LinearLayout) this.heading.getParent();
lay.requestLayout();
}
这让我发疯:/
根据注释,您希望在更改视图时更改 viewFlipper 的"标题"。由于您正在调用父级并调用 requestLayout,因此只需将超级调用移动到 last,这样您就不需要调用 requestlayout。
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
Log.i(TAG, "flipper onLayout");
int idx = this.getDisplayedChild();
Log.i(TAG, "flipper displayed child is: " + idx);
this.heading.cols_widths = some_cols_widths;
this.heading.resize_cols();
super.onLayout(changed, left, top, right, bottom);
}
或者你可以让 resize_cols() 调用 requestLayout 本身。
所以答案就像尼尼奥在上面写的:
"使用 postDelay 调用 requestLayout。