我有这个GUI:
的LinearLayout
-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();
}
这让我很生气:/
答案 0 :(得分:2)
根据评论,您希望在更改视图时更改viewFlipper的“标题”。由于您正在呼叫父母并呼叫requestLayout,只需将超级呼叫移至最后,因此您无需呼叫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本身。
答案 1 :(得分:1)
所以答案就像nininho写的那样:
“使用postDelayed来调用requestLayout。”