在TableLayout中交换两个按钮位置

时间:2010-07-21 22:22:55

标签: android 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

在询问我到目前为止所尝试的内容之前,我甚至不知道从哪里开始。我用谷歌搜索,但我能找到的唯一答案是关于AbsoluteLayout,这不是我需要的。

1 个答案:

答案 0 :(得分:1)

当你说“交换”时,你的意思是什么?我想你正在谈论动态地做它,否则你只是在布局中这样做。

交换的目的究竟是什么?只是替换文字?如果是这种情况,您只需在要更改的按钮上调用setText()即可。

编辑(在通过评论澄清问题之后):如果你想移动它们并为其设置动画,那么AbsoluteLayout将会工作,除了它已被弃用。还有其他布局,例如使用RelativeLayout并从左上角指定绝对偏移,甚至是GridView。然后,您可以使用TranslateAnimation移动按钮。