交换在TableLayout两个按钮位置 [英] Swap two buttons positions in TableLayout
问题描述
假设我有以下布局
<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>
我怎么能交换的 button01
与 button02
持何立场?并且将它也适用于交换 button01
与 button05
?
How could I swap position of button01
with button02
? And would it work also for swapping button01
with button05
?
在问什么我都试过,到目前为止,我甚至不知道从哪里开始。我用Google搜索,但唯一的答案,我能找到的关于 AbsoluteLayout
,这不是我所需要的。
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.
到底是什么交换的目的是什么?刚刚替换的文字?如果是这样的话,你可以简单地调用的setText()
上任何按钮,你想改变。
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.
编辑(澄清通过注释的问题后):如果你想移动它们和动画这一点,那么AbsoluteLayout会工作,但它的pcated德$ P $。还有其他的布局,就像使用RelativeLayout的和从左上角,或甚至一个GridView指定绝对偏移。然后,您可以使用TranslateAnimation移动的按钮。
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.
这篇关于交换在TableLayout两个按钮位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!