作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试弄清楚如何使我的布局将以下编码按钮保留在其位置,尽管 future 存在动态 Activity ,也许可以通过保留可用空间来实现。在菜单按钮和其他三个按钮之间将是一个按钮网格,其大小和数量都是随机的,基于动态创建的预选。但无论有多少按钮或大小,我都希望 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”,现在动态添加的任何按钮都可以根据需要放置在中间。
该网站不允许我回答自己的问题。
最佳答案
使您的RelativeLayout成为LinearLayout。给所有按钮“android:layout_weight=”0””。然后在所需的空白处添加一个具有 android:layout_height="0"和 "android:layout_weight="1""的 View 。如果我正确理解你的问题,应该可以了。
关于java - 如何为 future 的动态 Activity 留出空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11044609/
我是一名优秀的程序员,十分优秀!