如何在Android中创建标题内容布局? [英] How to create a header-content layout in Android?

查看:87
本文介绍了如何在Android中创建标题内容布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Android中创建以下布局?

我想要一个标题",即标题始终保持不变.唯一应该更改的是标头下方的区域.

将其视为网页,其中内容区域就是所有发生的地方=)

+--------------------+
| H E A D E R        |
+--------------------+
|                    |
|                    |
|                    |
|  C O N T E N T     |
|                    |
|                    |
|                    |
+--------------------+

当然可以轻松地创建LinearLayot,在顶部添加一个View,然后在其下方添加另一个视图-tada!但是,我要介绍的是您如何设置"或设计项目,以便轻松更改内容中的内容.

我真正想要的是能够滑动"(请参阅​​我真正想念的是一个完整的布局示例库.

您可以为标题创建布局文件.在每个内容活动的布局顶部,包括如下布局文件:

<include android:id="@+id/header"
         layout="@layout/my_header"
         android:layout_height="wrap_content"
         android:layout_width="fill_parent"/>

如何使标题保持在内容布局的顶部,将取决于其余的布局.您可以在include语句上使用带有"="="垂直的LinearLayout或带有align_parentTop =" true的相对布局.

Android文档很好地总结了基本布局类型.

How do I go about creating the following layout in Android?

I want a "header", that is, a header that stays the same at all times. The only thing that should change is the area below the header.

Think of it as a webpage, where the content-area is where its all happening =)

+--------------------+
| H E A D E R        |
+--------------------+
|                    |
|                    |
|                    |
|  C O N T E N T     |
|                    |
|                    |
|                    |
+--------------------+

Sure, its easy enough to create a LinearLayot, add a View on the top and then another view below that - tada! But what Im after is how you "set up" or design the project so its easy to just change whats in the Content.

What I really would like is to be able to "swipe" (see here) the area and then just "roll in" a new View/thing in the Content-area, but keep the same header.

What I really miss is a comprehensive library of layout-examples.

解决方案

You can create a layout file for your header. At the top of the layout for each content activity, include the layout file like:

<include android:id="@+id/header"
         layout="@layout/my_header"
         android:layout_height="wrap_content"
         android:layout_width="fill_parent"/>

How exactly you get the header to stay at the top of the content's layout will vary based on the rest of your layout. You could use a LinearLayout with orientation="vertical", or a relative layout with align_parentTop="true" on your include statement.

This android documentation has a good summary of basic layout types.

这篇关于如何在Android中创建标题内容布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆