Android TableLayout contains custom view only displays first row -
i want add custom view tablelayout following code:
my custom view class:
public class mycustomview extends view{ ... @override protected void ondraw(canvas canvas) { super.ondraw(canvas); //draw on canvas } } added view table layout in class:
public class mytableview extends tablelayout{ .... private void addviews(int column,int row){ (int = 0; < row; i++) { tablerow tablerows = new tablerow(mcontext); (int j = 0; j < column; j++) { mycustomview myview= new mycustomview(); tablerows.addview(dayview); } addview(tablerows); } } }
the table displays first row:
| mycustomview | mycustomview | mycustomview |
but if change mycustomview inherit textview:
public class mycustomview extends textview the table correctly displays rows:
| mycustomview | mycustomview | mycustomview |
| mycustomview | mycustomview | mycustomview |
| mycustomview | mycustomview | mycustomview |
what textview have view doesn't causing difference in tablelayout?
should add custom view?
note: tried set layout tablelayout.paramlayout layoutparamater of view, doesn't work either.
thanks.
i found need override onmeasure() in custom view if want use wrap_content custom view's layout param parent layout tablelayout can correctly recognize height of custom view , display correctly.
this post has great explanation this.
or specifying height of custom view using layout param instead of using wrap_content works also.
Comments
Post a Comment