Android:布置一堆简单的盒子?

Android:布置一堆简单的盒子?,第1张

概述这应该很容易,但对于我的生活,我无法弄明白. 我想制作一堆盒子,如下图所示: +------------------+| +------o-------+ || | Banner | || +------o-------+ || | Buttons | || | | || +------o-------+ || | 这应该很容易,但对于我的生活,我无法弄明白.
我想制作一堆盒子,如下图所示:

+------------------+| +------o-------+ || |  Banner      | || +------o-------+ || | buttons      | || |              | || +------o-------+ || |              | || |              | || | VIEwFlipper  | || |              | || |              | || |              | || |              | || +------o-------+ || | buttons      | || +------o-------+ || | Footer       | || +------o-------+ |+------------------+

每个框 – 包括外部框 – 表示包含其他窗口小部件(甚至是单独的窗口小部件)的布局.外框与设备的宽度和高度相匹配.堆栈的宽度和高度必须与外部容器匹配.盒子的边缘彼此粘合并粘合到容器的顶部和底部边缘,如’o’所示.所有内部布局都紧紧包裹其内容,除了最大的 – 一个VIEwFlipper – 它包含一个可滚动的列表框,可以根据需要进行扩展或收缩.盒子的数量并不重要,只要它是四个或更多.

VIEwFlipper包含许多垂直linearLayouts,宽度/高度= fillparent(我的理解是父级是VIEwFlipper).

到目前为止,我尝试使用外部relativeLayout并将内部框的边缘缝合成:
androID:layout_below =“@ ID / former_Box和androID:layout_above =”@ ID / following_Box,但这是一个不稳定的情况,盒子开始表现得很奇怪(比如第二个完全覆盖其他的等等)每次我改变设计(例如,插入另一个中间盒).请注意,这是一个设计时布局,不涉及花哨的动态运行时重新排列.

我现在正在尝试使用tableLayout(单个列),基本上没有值得报道的快乐.我显然不是AndroID专家,但仍然.做这个的最好方式是什么?

编辑 – 插入实际代码
由于省略实际代码似乎使问题模糊(我希望它会澄清它,我的错误)我在这里插入工作版本.您会注意到它没有横幅和页脚.如上所述,每当我尝试插入额外的盒子时,它都会在我身上爆炸 – 经常主演的循环参考.

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"        xmlns:tools="http://schemas.androID.com/tools"        androID:layout_margin="0dip"                androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:orIEntation="vertical"         tools:context=".TomActivity" >  <relativeLayout      androID:ID="@+ID/spinnerBox"      androID:layout_wIDth="match_parent"      androID:layout_height="wrap_content"      androID:gravity="center_horizontal"      androID:onClick="left"      androID:layout_alignParenttop="true"      androID:layout_alignParentleft="true"      androID:layout_alignParentRight="true"      androID:orIEntation="horizontal" >    <button        androID:ID="@+ID/leftarrow"    androID:background="#888888"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:gravity="left"        androID:minHeight="0dip"        androID:minWIDth="0dip"        androID:layout_alignParentleft="true"               androID:onClick="left"        androID:text="button" />    <TextVIEw    androID:ID="@+ID/spinTitle"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_toRightOf="@+ID/leftarrow"    androID:layout_toleftOf="@+ID/rightarrow"    androID:layout_centerInParent="true"    androID:layout_toEndOf="@+ID/leftarrow"    androID:layout_toStartOf="@+ID/rightarrow"    androID:gravity="center"    androID:text="Label" />    <button    androID:ID="@+ID/rightarrow"    androID:background="#888888"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_alignParentRight="true"    androID:gravity="right"    androID:minHeight="0dip"    androID:minWIDth="0dip"    androID:onClick="right"    androID:text="button"     />  </relativeLayout>  <VIEwFlipper      androID:ID="@+ID/vIEw_flipper"      androID:layout_margin="0dip"            androID:layout_alignParentleft="true"      androID:layout_alignParentRight="true"      androID:layout_below="@+ID/spinnerBox"      androID:layout_above="@+ID/buttonBox"      androID:layout_wIDth="fill_parent"      androID:layout_height="fill_parent">    <linearLayout    androID:layout_margin="0dip"                androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:gravity="center" >      <ListVIEw      androID:ID="@+ID/CoursesVIEw"      androID:layout_margin="0dip"            androID:background="#ffffff"      androID:layout_wIDth="match_parent"      androID:layout_height="wrap_content"      androID:layout_weight="1" >      </ListVIEw>    </linearLayout>    <linearLayout    androID:layout_margin="0dip"                androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:gravity="center" >      <ListVIEw      androID:ID="@+ID/FutureCoursesVIEw"      androID:layout_margin="0dip"      androID:background="#ffffff"            androID:layout_wIDth="match_parent"      androID:layout_height="wrap_content"      androID:layout_weight="1" >      </ListVIEw>    </linearLayout>    <linearLayout    androID:layout_margin="0dip"                androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:gravity="center" >      <ListVIEw      androID:ID="@+ID/MessagesVIEw"      androID:layout_margin="0dip"      androID:background="#ffffff"        androID:layout_wIDth="match_parent"      androID:layout_height="wrap_content"      androID:layout_weight="1" >      </ListVIEw>    </linearLayout>       </VIEwFlipper>  <linearLayout      androID:ID="@+ID/buttonBox"      androID:layout_wIDth="match_parent"      androID:layout_height="wrap_content"      androID:layout_alignParentleft="true"      androID:layout_alignParentRight="true"      androID:layout_alignParentBottom="true"      androID:orIEntation="horizontal"      >    <button    androID:ID="@+ID/CurrentCoursesbutton"    androID:background="#888888"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:layout_weight="1"    androID:text="button" />    <button    androID:ID="@+ID/FutureCoursesbutton"    androID:background="#888888"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:layout_weight="1"    androID:text="button" />    <button    androID:ID="@+ID/UnreadMessagesbutton"    androID:background="#888888"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:layout_weight="1"    androID:text="button" />    <button    androID:ID="@+ID/Refreshbutton"    androID:background="#888888"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:layout_weight="1"    androID:onClick="refreshAll"    androID:text="button" />    <button    androID:ID="@+ID/logoffbutton"    androID:background="#888888"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:layout_weight="1"    androID:onClick="logoff"    androID:text="button" />  </linearLayout></relativeLayout>

干杯,

编辑以更清楚地显示布局并提供有关基本原理的信息

解决方法 在构建复杂/多级布局时,首先准备最内层布局.然后迭代地将您的外部布局包裹在最里面的布局周围.这样,决定使用哪个布局容器有点简化.

看看以下是否符合您的要求:

我在这里发布了Layout的xml:Link(pastebin) Link(file)

我所做的是使用您提供的布局并将其放置在垂直方向的linearLayout中.顶部和底部的“横幅”给出layout_weight =“0”,而内容区域(您给出的代码)的layout_weight设置为1.因此,顶部和底部横幅占用固定数量的空间,内容需要其余的.

总结

以上是内存溢出为你收集整理的Android:布置一堆简单的盒子?全部内容,希望文章能够帮你解决Android:布置一堆简单的盒子?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1123260.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存