代码之家  ›  专栏  ›  技术社区  ›  Federico klez Culloca

交换TableLayout中的两个按钮位置

  •  0
  • Federico klez Culloca  · 技术社区  · 14 年前

    假设我有以下布局

    <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 ? 它是否也适用于交换 按钮01 button05 ?

    AbsoluteLayout ,这不是我需要的。

    1 回复  |  直到 14 年前
        1
  •  1
  •   EboMike    14 年前

    你说“交换”是什么意思?我想你说的是动态地做,否则就在布局中做。

    交换的目的到底是什么?只是替换文本?如果是这样的话,你可以打个电话 setText() 无论你想换哪个按钮。

    编辑(在通过评论澄清问题之后):如果你想移动它们并设置动画,那么AbsoluteLayout就可以了,只是不推荐使用。还有其他布局,比如使用RelativeLayout和指定从左上角的绝对偏移,甚至是GridView。然后可以使用TranslateAnimation来移动按钮。