如何找出表格布局内视图的行/列

发布于 2024-08-21 02:08:34 字数 219 浏览 3 评论 0原文

假设我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只是偏爱你 2024-08-28 02:08:34

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).

忱杏 2024-08-28 02:08:34

TableLayout类中没有这样的getIndexOfChild(view),而是有一个indexOfChild()!

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

谈场末日恋爱 2024-08-28 02:08:34

在代码中设计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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文