Android 如何从onLayout重新加载接口?

Android 如何从onLayout重新加载接口?,android,layout,reload,Android,Layout,Reload,我有一个GUI: 线性布局 -TableLayout heading -ViewFlipper flipper - TableLayout1 - TableLayout2 - TableLayout3 ... (dynamicly added) 我更改了vf.onLayout(..)中t1的宽度,但我无法重新绘制它。。。。请帮助:/ 代码如下: @Override protected void onLayout(boolean changed, int

我有一个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本身。

因此答案就像nininho在上面写的那样:


“使用postDelayed调用requestLayout。”

在上更改布局不是一个好主意onLayout@nininho好的,那么在布局第二个视图之后,哪里是更新第一个视图的好地方呢?:)当您更改/翻转到另一个视图时,它将再次布局和绘制,因此无需更新不可见的视图。@nininho“不可见的视图”是什么意思?我想根据ViewFlipper中当前显示的表中的值更改Tablelayout(不在ViewFlipper中)中的宽度。很抱歉造成混淆,但是..'此.heading'位于ViewFlipper之外。要设置的表格布局取决于ViewFlipper中表格(当前显示)的布局。目前,我正试图通过getChildDrawingOrder(int childCount,int i)更改绘图顺序,但没有效果。从您的图中可以看出,Flipper和TableLayout处于同一级别,因此它们的父级是相同的,超级可以工作,但它是一个线性布局,所以当ViewFlipper处于打开状态时,表已经处于布局状态,在布局过程中调用requestLayout可能已被讨论。因此,如果您事先已经知道列宽,请在更改VIewFlipper之前调用resize_cols(),或者使用postDelayed调用requestLayout。因此,问题在于标题布局依赖于后来生成的VIewFlipper flipper布局。解决方案是在flipper.onLayout中使用postDeyaled(更具体地说,我只使用Post)和heading.requestLayout()。很好用。。尼尼尼奥是神:)