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_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#fff" >

    <!--使用相对布局,头部在最顶,底部在最低,中部相对两者中间->
    <!--头部-->
    <RelativeLayout
        android:id="@+id/rlhead"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/main_header_bg"
        android:gravity="center" >
    </RelativeLayout>

    <!--中部-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/rlfoot"
        android:layout_below="@+id/rlhead"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:background="@color/common_white"
        android:orientation="vertical"
        android:scrollbars="none" >

    </LinearLayout>

    <!--尾部-->
    <include
        android:id="@+id/rlfoot"
        layout="@layout/widget_menu" />

</RelativeLayout>

第二种使用比重:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#fff" >

    <!--头部-->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/main_header_bg"
        android:gravity="center" >
    </RelativeLayout>

    <!--使用线性布局,头部在最顶,底部在最低,中部采用比重占剩余比重的全部-->
    <!--中部-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/common_white"
        android:orientation="vertical"
        android:scrollbars="none"
        android:layout_weight="1">

    </LinearLayout>

    <!--尾部-->
    <include
        layout="@layout/widget_menu" />

</LinearLayout>
时间: 2024-07-30 13:45:32

Android开发(十八)——头部、中部、底部布局技巧的相关文章

二十八个 HTML5 特性与技巧

1. New Doctype  你还在使用令人讨厌的难记的XHTML文档类型声明吗?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>如果还在用,为什么呢?如同Douglas Quaid所说,转到新的HTML5这种文档类型吧,它会使你看起来更年轻.实际上,你当真知道XHTML的文档类型声明

【转】Android开发学习笔记:5大布局方式详解

Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(TableLayout):按照行列方式布局组件. 相对布局(RelativeLayout):相对其它组件的布局方式. 绝对布局(AbsoluteLayout):按照绝对坐标来布局组件. 1. 线性布局 线性布局是Android开发中最常见的一种布局方式,它是按照垂直或者水平方向来布局,通过“android:

Android开发:View的几种布局及实践

引言 View的布局显示方式有下面几种:线性布局(Linear Layout).相对布局(Relative Layout).表格布局(Table Layout).网格视图(Grid View).标签布局(Tab Layout).列表视图(List View).绝对布局(AbsoluteLayout).本文虽然是介绍View的布局方式,但不仅仅是这样,其中涉及了很多小的知识点,绝对能给你带来Android大餐! 本文的主要内容就是分别介绍以上视图的七种布局显示方式效果及实现,大纲如下: 1.Vie

Android开发关闭虚拟按钮、底部导航条

在Android开发中,遇到了一系列大大小小的问题,其中一个就是屏蔽底部实体键,我找了很多的博客也尝试了许许多多的方法,但始终不能屏蔽 HOME键,后来看见一篇博客说在Android 4.0以后,屏蔽底部HOME键必须反编译,修改Android底部原生代码,于是我便放弃了.废话不多说,我先分享一个屏蔽Android虚拟按键的方法,以及最简单的屏蔽Android的Back按钮,适合所有版本(未测试,感觉是这样): 1. Android 屏蔽Back按键 只需要重写 onKeyDown 方法就可以了

android学习十八(Service服务的基本用法)

定义一个服务 在项目中定义一个服务,新建一个ServiceTest项目,然后在这个项目中新增一个名为MyService的类,并让它继承自Service,完成后的代码如下所示: package com.jack.servicetest; import android.app.Service; import android.content.Intent; import android.os.IBinder; public class MyService extends Service { @Over

android开发(1):底部导航条的实现 | navigation tab | activity的创建

底部导航条,在iOS中叫tabbar,在android中叫bottombar或bottom navigation,是一个常用的切换页面的导航条. 同样,如果有良好的第三方库,我们应该优先考虑,能用好别人的东西,已经很厉害. github上的roughike/BottomBar,曾经是热度较高的库,但是已经过时了,没有再维护,加到项目也会遇到编译的问题,所以这里不使用,这里使用的是PagerBottomTabStrip,地址是:https://github.com/tyzlmjj/PagerBot

android开发(1):底部导航条的实现 | navigation tab

底部导航条,在iOS中叫tabbar,在android中叫bottombar或bottom navigation,是一个常用的切换页面的导航条. 同样,如果有良好的第三方库,我们应该优先考虑,能用好别人的东西,已经很厉害. github上的roughike/BottomBar,曾经是热度较高的库,但是已经过时了,没有再维护,加到项目也会遇到编译的问题,所以这里不使用,这里使用的是PagerBottomTabStrip,地址是:https://github.com/tyzlmjj/PagerBot

Android第十八期 - 智能机器人

这回比较复杂,所以就一步步的教学弟们怎么写出来一个可以和你聊天的智能机器人Android版. 首先我们找一个第三方的api接口,我选择的是图灵机器人,地址是http://www.tuling123.com/openapi/,  如图:     然后是找到api文档接入口:     然后是json的解析部分: 然后我们挑一个做一个demo - 一问一答的例子: 那么调用的方式url = http://www.tuling123.com/openapi/api?key=ad5f0729523118c

Android入门(十八)服务

原文链接:http://www.orlion.ga/674/ 一.定义一个服务 创建一个项目ServiceDemo,然后在这个项目中新增一个名为 MyService的类,并让它继承自 Service,完成后的代码如下所示: public class MyService extends Service {     @Override     public IBinder onBind(Intent intent) {         return null;     } } onBind()方法是