开发者

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

开发者 https://www.devze.com 2022-12-19 20:50 出处:网络
Suppose I hav开发者_JAVA百科e a view inside TableLayout, like this: TableLayout tableLayout; View view = (View)tableLayout.findViewById(R.id.control);

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

精彩评论

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