【问题标题】:Swap two buttons positions in TableLayout在 TableLayout 中交换两个按钮位置
【发布时间】:2011-04-16 05:58:47
【问题描述】:

假设我有以下布局

<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 交换?它是否也适用于将button01button05 交换?

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

【问题讨论】:

    标签: android tablelayout


    【解决方案1】:

    当您说“交换”时,您是什么意思?我想您是在谈论动态执行它,否则您只需在布局中执行它。

    交换的具体目的是什么?只是替换文字?如果是这种情况,您只需在要更改的任何按钮上调用 setText()

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

    【讨论】:

    • @EboMike 我认为klez 的意思是交换两个按钮的位置。但你是对的,“交换”可以通过切换文本(和其他外观)和回调处理程序来模拟。
    • 这是一个 15 个谜题,所以我希望也能为交换设置动画。
    • 啊,所以你不想只是交换它们,你想物理移动它们?好吧,AbsoluteLayout 可以工作,只是它已被弃用。还有其他布局,例如使用 RelativeLayout 并指定从左上角的绝对偏移量,甚至是 GridView。然后,您可以使用 TranslateAnimation 来移动按钮。
    • @EboMike:您能否编辑您的答案,或发布另一个关于 RelativeLayout 的答案,以便我接受?
    • 仍在寻找答案:/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    • 2021-07-08
    • 1970-01-01
    • 2014-10-15
    • 2022-09-23
    • 1970-01-01
    相关资源
    最近更新 更多