Swap two buttons positions in TableLayout
Suppose I have the foll开发者_开发技巧owing layout
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableLayout">
<TableRow android:id="@+id/TableRow01" >
<Button android:text="1" android:id="@+id/button01"/>
<Button android:text="2" android:id="@+id/button02"/>
<Button android:text="3" android:id="@+id/button03"/>
<Button android:text="4" android:id="@+id/button04"/>
</TableRow>
<TableRow android:id="@+id/TableRow01" >
<Button android:text="5" android:id="@+id/button05"/>
<Button android:text="6" android:id="@+id/button06"/>
<Button android:text="7" android:id="@+id/button07"/>
<Button android:text="8" android:id="@+id/button08"/>
</TableRow>
</TableLayout>
How could I swap position of button01
with button02
? And would it work also for swapping button01
with button05
?
Before asking what I have tried so far, I don't even know where to start. I googled but the only answer I could find was about AbsoluteLayout
, which is not what I need.
When you say "swap", what do you mean? I suppose you're talking about doing it dynamically, or else you'd just do it in the layout.
What exactly is the purpose of the swapping? Just replacing the text? If that's the case, you could simply call setText()
on whichever button you want to change.
EDIT (after clarifying the question via comments): If you want to move them and animate that, then AbsoluteLayout WOULD work, except that it's deprecated. There are other layouts, like using a RelativeLayout and specifying absolute offsets from the top left, or even a GridView. You could then use a TranslateAnimation to move the buttons.
精彩评论