Tablelayout 和 LinearLayout - 可见和不可见

发布于 2024-11-25 10:57:25 字数 492 浏览 2 评论 0原文

我想要在线性布局内有一个表格布局,以便表格布局之前和之后都有文本。问题是我希望能够在 2 个表(表 1 和表 2)之间切换,但保持前后文本相同。我认为这可以使用表格布局的可见和不可见功能进行管理,并在一个布局中定义整个内容,但情况似乎并非如此。我得到的是,当我使 Table2 可见而 Table1 不可见时,Table2 会向下移动,因为我在布局中的 Table 1 之后定义了它。

我想要的是:- 这里有一些文字 表1 SomeTextHere

SomeTextHere 表2 SomeTextHere 也是

我得到的是:-

SomeTextHere 表1 SomeTextHere 也是

SomeTextHere

表2 SomeTextHere

我也尝试过:-

LinearLayout TableLayout1 可见 TableLayout2 使不可见 LinearLayout

有什么想法吗?

I want to have a table layout inside a linear layout so that there is text before and after the table layout. The issue is that I want to be able to switch between 2 tables (Table1 and Table2) but keep the text before and after the same. I thought that this would be manageable using visible and invisible features of tablelayout and define the whole thing in one layout but this doesnt seem to be the case. What I get is that when I make Table2 visible and Table1 invisble that Table2 is shifted down because I have defined it after Table 1 in the layout.

What I want is:-
SomeTextHere
Table1
SomeTextHere too

or

SomeTextHere
Table2
SomeTextHere too

What I get is:-

SomeTextHere
Table1
SomeTextHere too

SomeTextHere

Table2
SomeTextHere too

I have tried:-

LinearLayout
TableLayout1 make visible
TableLayout2 make invisible
LinearLayout

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

过度放纵 2024-12-02 10:57:25

如果我正确地回答了你的问题,我认为你可以做的是在主 LinearLayout 中添加两个以上的 LinearLayout。然后将组(文本,表格,文本)放入每个 LinearLayout 中,然后你可以使用每个 LinearLayout 而不是使用文本,table,text

这样你的布局层次结构看起来像

< LinearLayout>

        < LinearLayout>

             < Text>
             < TableLayout>
             < Text>

    < /LinearLayout>

    < LinearLayout>

            < Text>
            < TableLayout>
            < Text
     < /LinearLayout>

    < /LinearLayout>

If i got your question correctly i think what you can do is adding two more LinearLayout in your main LinearLayout.Then put the group (Text,Table,Text) in each LinearLayout and then you can work with each Linear Layout instead of working with text,table,text

So that your layout hierarchy looks like

< LinearLayout>

        < LinearLayout>

             < Text>
             < TableLayout>
             < Text>

    < /LinearLayout>

    < LinearLayout>

            < Text>
            < TableLayout>
            < Text
     < /LinearLayout>

    < /LinearLayout>
夏末染殇 2024-12-02 10:57:25

您的问题是您正在使用 View.INVISIBLE 来隐藏这些部分。如果您希望视图不占用布局中的空间,则需要使用 View.GONE。

此外,如果仅更改表,则无需重复,只需将表一个接一个地放置,并将默认情况下不可见的表的可见性设置为消失。然后你可以在代码中切换它们。

Your problem is you're using View.INVISIBLE to hide the sections. You need to use View.GONE if you want a view to not take up space in a layout.

Also if only the table is changed then you don't need to duplicate just put the tables one after the other and set the visibility of the one that shouldn't be visible by default set to gone. Then you can just toggle them in code.

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