I want to have a table l开发者_如何学Pythonayout 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?
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>
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.
精彩评论