如何找出表格布局内视图的行/列
假设我在 TableLayout 中有一个视图,如下所示:
TableLayout tableLayout;
View view = (View)tableLayout.findViewById(R.id.control);
How can I find out the view's row/column inside the TableLayout?
Suppose I have 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
TableRow 内的视图应将 TableRow.LayoutParams 作为其 LayoutParams。从那里你可以得到layout_column。
行似乎有点困难。我希望 TableLayout.LayoutParams (从 TableRow 获取)具有该信息,但似乎没有。您可以尝试使用 tableLayout.getIndexOfChild(rowView)。
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).
TableLayout类中没有这样的getIndexOfChild(view),而是有一个indexOfChild()!
There is no such getIndexOfChild(view) in TableLayout class, but a indexOfChild()!
在代码中设计tablerow时,可以使用setTag()将其设置为行号。稍后可以通过 tableRow.getTag() 检索它。在 xml 中,您可以使用 android:tag="2"。
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".