4

我有这个图形用户界面:

线性布局

-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();    
 }

这让我发疯:/

4

2 回答 2

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 本身。

于 2012-06-15T18:27:30.757 回答
1

所以答案就像 nininho 上面写的:

“使用 postDelayed 调用 requestLayout。”

于 2012-07-01T08:40:56.070 回答