【问题标题】:How to leave area for future dynamic activity?如何为未来的动态活动留出区域?
【发布时间】:2012-06-15 04:31:10
【问题描述】:

我试图弄清楚如何使我的布局使以下编码按钮保持在原位,尽管未来有动态活动,可能是通过保留可用空间。在菜单按钮和其他三个按钮之间将是一个按钮网格,其大小和数量都是随机的,基于动态创建的预选。但无论有多少按钮或大小,我都希望 main.xml 中设计的这四个按钮保持在适当的位置。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/menu"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="MENU" />

这是值得关注的领域。我想让菜单按钮(上方)始终连接到屏幕顶部,而步进、暂停和模拟按钮(下方)始终位于屏幕的最底部。

    <Button
        android:id="@+id/step"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/grid"
        android:layout_centerHorizontal="true"
        android:text="STEP" />

    <Button
        android:id="@+id/pause"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/grid"
        android:layout_toLeftOf="@id/step"
        android:text="PAUSE" />

    <Button
        android:id="@+id/sim"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/grid"
        android:layout_toRightOf="@id/step"
        android:text="SIMULATE" />

    <SeekBar
        android:id="@+id/speed"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/sim"
        android:layout_alignParentLeft="true"/>

</RelativeLayout>

我只是想出了一个解决方案我自己的问题。 我不得不在其他三个按钮上的菜单按钮之后使用“android:layout_alignParentBottom="true",现在可以根据需要将任何动态添加的按钮放在两者之间。

网站不让我回答我自己的问题。

【问题讨论】:

  • 每当您使用“Android 中的动态布局”一词时,您都需要查看 Java 代码。相比之下,XML 相当僵化和静态。

标签: java android xml button


【解决方案1】:

将您的 RelativeLayout 设为 LinearLayout。给所有按钮“android:layout_weight="0"”。然后在所需的空白处,添加一个具有 android:layout_height="0" 和 "android:layout_weight="1"" 的视图。只要我正确理解您的问题,就应该这样做。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多