Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android:布置一堆简单的盒子?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这应该很容易,但对于我的生活,我无法弄明白.
我想制作一堆盒子,如下图所示:

+------------------+
| +------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://scheR_134_11845@as.android.com/apk/res/android"
        xmlns:tools="http://scheR_134_11845@as.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:布置一堆简单的盒子?所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。