Ali*_*orm 3 android android-layout
这应该很容易,但对于我的生活,我无法弄明白.我想制作一堆盒子,如下图所示:
+------------------+
| +------o-------+ |
| | Banner | |
| +------o-------+ |
| | Buttons | |
| | | |
| +------o-------+ |
| | | |
| | | |
| | ViewFlipper | |
| | | |
| | | |
| | | |
| | | |
| +------o-------+ |
| | Buttons | |
| +------o-------+ |
| | Footer | |
| +------o-------+ |
+------------------+
Run Code Online (Sandbox Code Playgroud)
每个框 - 包括外部框 - 表示包含其他窗口小部件(甚至是单独的窗口小部件)的布局.外框与设备的宽度和高度相匹配.堆栈的宽度和高度必须与外部容器匹配.盒子的边缘彼此粘合并粘合到容器的顶部和底部边缘,如'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>
Run Code Online (Sandbox Code Playgroud)
干杯,
编辑以更清楚地显示布局并提供有关基本原理的信息
在构建复杂/多级布局时,首先准备最内层布局.然后迭代地将您的外部布局包裹在最里面的布局周围.这样,决定使用哪个布局容器有点简化.
看看以下是否符合您的要求:

我在这里发布了Layout的xml:链接(pastebin) 链接(文件)
我所做的是使用您提供的布局并将其放置在垂直方向的LinearLayout中.layout_weight="0"当内容区域(您给出的代码)layout_weight设置为时,会给出顶部和底部"横幅" 1.因此,顶部和底部横幅占用了固定的空间,内容占用了其余部分.
| 归档时间: |
|
| 查看次数: |
367 次 |
| 最近记录: |