开发者

How can I find out the row /column of a view inside table layout

Suppose I hav开发者_JAVA百科e a view inside TableLayout, like this:

TableLayout tableLayout;
View view = (View)tableLayout.findViewById(R.id.control);

How can I find out the view's row/column within the TableLayout?


A view that is within a TableRow should have TableRow.LayoutParams as its LayoutParams. From that you can get the layout_column.

The row seems to be a bit harder. I'd expect the TableLayout.LayoutParams (gotten from the TableRow) to have that information, but it doesn't seem to. You could try using tableLayout.getIndexOfChild(rowView).


There is no such getIndexOfChild(view) in TableLayout class, but a indexOfChild()!


While designing the tablerow in code, you can use setTag() to set it to row number. Later it can be retrieved by tableRow.getTag(). In xml you may use android:tag="2".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜