如何为android系统的线性布局中的页眉和页脚 [英] How to set the header and footer for linear layout in android

查看:179
本文介绍了如何为android系统的线性布局中的页眉和页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何设置相对布局和中心点固定的页眉和页脚?我要动态添加的WebView的滚动并添加阵列时,我想滚动中心点只在Android的滚动。任何人都可以举个例子?

我试过,但中间部分的WebView没有出现适当的,有什么改变?

我的XML code是

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android机器人:ID =@ + ID / mainrelativelayout的android:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT&GT ;


    
    
    
    
    
    
    

 <的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
  机器人:ID =@ + ID / linear1机器人:layout_height =WRAP_CONTENT
    机器人:方向=横向  ><的TextView的android:paddingRight =75dip机器人:paddingLeft =20dip机器人:文本=索引机器人:ID =@ + ID / TextView01的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑白机器人:文字样式=大胆>< / TextView的>
<的TextView的android:paddingRight =60dip机器人:文本=最后机器人:ID =@ + ID / TextView02的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑色的机器人:文字样式=大胆>< / TextView的>
<的TextView的android:文本=更改机器人:ID =@ + ID / TextView03的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑白机器人:TEXTSTYLE =大胆>< / TextView的>
< / LinearLayout中>
<的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
   机器人:ID =@ + ID / linear1机器人:layout_height =6DIP
     机器人:方向=横向   >< ImageView的机器人:ID =@ + ID / ImageView08机器人:layout_gravity =中心的android:背景=@绘制/线路的android:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT>< / ImageView的>
< / LinearLayout中>
<的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =WRAP_CONTENT
  机器人:ID =@ + ID / linear2
  机器人:方向=横向  >
 < ImageView的机器人:ID =@ + ID / ImageView05机器人:paddingTop =5dip机器人:layout_gravity =中心的android:背景=@绘制/下降的android:layout_width =WRAP_CONTENT机器人:layout_height = WRAP_CONTENT>< / ImageView的>
 <的TextView的android:paddingRight =30dip机器人:paddingLeft =10dip机器人:文本=机器人:ID =@ + ID / txtindex0的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑白机器人:TEXTSIZE =12dip>< / TextView的>
<的TextView的android:paddingRight =55dip机器人:文本=机器人:ID =@ + ID / txtlast0的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑白机器人:TEXTSIZE =12dip>< / TextView的>
<的TextView的android:文本=机器人:ID =@ + ID / txtchange0的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:TEXTSIZE =12dip机器人:文字颜色=@彩色/ RED1 >< / TextView的>
< / LinearLayout中>
<的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =WRAP_CONTENT
  机器人:ID =@ + ID / linear3
  机器人:方向=横向  >
< ImageView的机器人:ID =@ + ID / ImageView02机器人:layout_gravity =中心的android:背景=@绘制/向上的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< / ImageView的>
<的TextView的android:paddingRight =46dip机器人:paddingLeft =10dip机器人:文本=机器人:ID =@ + ID / txtindex1的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑白机器人:TEXTSIZE =12dip>< / TextView的>
<的TextView的android:paddingRight =64dip机器人:文本=机器人:ID =@ + ID / txtlast1的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑白机器人:TEXTSIZE =12dip>< / TextView的>
<的TextView的android:文本=机器人:ID =@ + ID / txtchange1的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:TEXTSIZE =12dip机器人:文字颜色=@彩色/ green1 >< / TextView的>
< / LinearLayout中><的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =WRAP_CONTENT
  机器人:ID =@ + ID / linear4
   机器人:方向=横向  >
< ImageView的机器人:ID =@ + ID / ImageView03机器人:layout_gravity =中心的android:背景=@绘制/向上的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< / ImageView的>
<的TextView的android:paddingRight =69dip机器人:paddingLeft =10dip机器人:文本=机器人:ID =@ + ID / txtindex2的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑白机器人:TEXTSIZE =12dip>< / TextView的>
<的TextView的android:paddingRight =67dip机器人:文本=机器人:ID =@ + ID / txtlast2的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑白机器人:TEXTSIZE =12dip>< / TextView的>
<的TextView的android:文本=机器人:ID =@ + ID / txtchange2的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:TEXTSIZE =12dip机器人:文字颜色=@彩色/ green1 >< / TextView的>< / LinearLayout中>
<的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =WRAP_CONTENT
  机器人:ID =@ + ID / linear4
    机器人:方向=横向  >
< ImageView的机器人:ID =@ + ID / ImageView04机器人:layout_gravity =中心的android:背景=@绘制/向上的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< / ImageView的>
<的TextView的android:paddingRight =61dip机器人:paddingLeft =10dip机器人:文本=机器人:ID =@ + ID / txtindex3的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑白机器人:TEXTSIZE =12dip>< / TextView的>
<的TextView的android:paddingRight =65dip机器人:文本=机器人:ID =@ + ID / txtlast3的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文字颜色=@彩色/黑白机器人:TEXTSIZE =12dip>< / TextView的>
<的TextView的android:文本=机器人:ID =@ + ID / txtchange3的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:TEXTSIZE =12dip机器人:文字颜色=@彩色/ green1 >< / TextView的>
< / LinearLayout中><的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
   机器人:ID =@ + ID / linear1机器人:layout_height =4dip
     机器人:方向=横向
      >< ImageView的机器人:ID =@ + ID / ImageView08机器人:layout_gravity =中心的android:背景=@绘制/线路的android:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT>< / ImageView的>
< / LinearLayout中><的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =15dip
  机器人:ID =@ + ID / linear5
  机器人:方向=横向  >
<的TextView的android:文本=市场数据延迟至少15分钟机器人:ID =@ + ID / TextView16的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:TEXTSIZE =12dip机器人:文字颜色=@色/ GRAY2>< / TextView的>
< / LinearLayout中>
< / LinearLayout中>
< ------整理头-------->

<添加---------- -----------页脚>

 <的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =WRAP_CONTENT
  机器人:ID =@ + ID / imglinear
  机器人:背景=@色/白
  机器人:layout_alignParentBottom =真
  >
< ImageView的机器人:ID =@ + ID / ImageView15机器人:SRC =@绘制/ quest_i机器人:layout_gravity =中心的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>< / ImageView的>
< / LinearLayout中>

< --------------整理页脚------->

< ------------屏幕中心点--------->

 < RelativeLayout的
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =WRAP_CONTENT
  机器人:方向=垂直
  机器人:背景=@色/白
  机器人:ID =@ + ID / mainlinear3
  机器人:layout_above =@ + ID / imglinear
  机器人:layout_below =@ + ID / mainlinear2
   >
  <滚动型机器人:ID =@ + ID / ScrollView01
     机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>
 < RelativeLayout的
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =WRAP_CONTENT
  机器人:方向=垂直
  机器人:背景=@色/白
  机器人:ID =@ + ID / relative3>  < / RelativeLayout的>
  < /滚动型>
< / RelativeLayout的>

< -----------中心点整理---------->

 < / RelativeLayout的>

感谢


解决方案

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>    <! - 头文件 - >
    <包括机器人:ID =@ + ID / top_header
        机器人:layout_alignParentTop =真正的布局=@布局/ layout_header/>
    <! - 页脚 - >
    <的LinearLayout机器人:ID =@ + ID / bottom_menu
        机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT
        机器人:方向=垂直机器人:layout_alignParentBottom =真正的>
        <! - 菜单栏 - >
        <包括布局=@布局/ layout_footer_menu/>
    < / LinearLayout中>    <! - 主体 - >
    <的LinearLayout机器人:方向=垂直
        机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT
        机器人:layout_below =@ ID / top_header机器人:layout_above =@ ID / bottom_menu
        机器人:layout_weight =1
        机器人:ID =@ + ID / sub_content_view
        机器人:paddingBottom会=5SP机器人:背景=#EAEAEA>
    < / LinearLayout中>
< / RelativeLayout的>

这是更好地设定为主要部分都:

安卓layout_below =@ ID / top_header
机器人:layout_above =@ ID / bottom_menu

在你的情况的内容将页脚和滚动条下方会显示不正确。

此外,你需要在code页脚处以上内容 - 安卓想看到的ID(@ ID / bottom_menu),如果它没有被之前定义

Can anybody tell me how to set a fixed header and footer for relative layout and center point? I want to add scrollable and adding array of webview dynamically when I want to scroll center point only scrollable in android. Can anybody give an example?

I tried but center part webview is not appearing properly, is there anything to change?

my xml code is

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:id="@+id/mainrelativelayout"  android:layout_width="fill_parent" android:layout_height="fill_parent"> 

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:id="@+id/linear1" android:layout_height="wrap_content"
    android:orientation="horizontal"

  >

<TextView  android:paddingRight="75dip" android:paddingLeft="20dip" android:text="Index" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textStyle="bold"></TextView>
<TextView android:paddingRight="60dip"   android:text="Last" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textStyle="bold"></TextView>
<TextView  android:text="Change" android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textStyle="bold"></TextView>
</LinearLayout>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
   android:id="@+id/linear1" android:layout_height="6dip"
     android:orientation="horizontal"

   >

<ImageView android:id="@+id/ImageView08" android:layout_gravity="center" android:background="@drawable/line" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageView>
</LinearLayout>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/linear2"
  android:orientation="horizontal"

  >
 <ImageView android:id="@+id/ImageView05" android:paddingTop="5dip" android:layout_gravity="center"  android:background="@drawable/down" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
 <TextView  android:paddingRight="30dip" android:paddingLeft="10dip"   android:text="" android:id="@+id/txtindex0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textSize="12dip"></TextView>
<TextView  android:paddingRight="55dip"  android:text="" android:id="@+id/txtlast0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textSize="12dip"></TextView>
<TextView     android:text="" android:id="@+id/txtchange0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12dip" android:textColor="@color/red1"></TextView>
</LinearLayout>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/linear3"
  android:orientation="horizontal"

  >
<ImageView android:id="@+id/ImageView02" android:layout_gravity="center" android:background="@drawable/up" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<TextView  android:paddingRight="46dip"  android:paddingLeft="10dip"    android:text="" android:id="@+id/txtindex1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textSize="12dip"></TextView>
<TextView  android:paddingRight="64dip"  android:text="" android:id="@+id/txtlast1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textSize="12dip"></TextView>
<TextView  android:text="" android:id="@+id/txtchange1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12dip" android:textColor="@color/green1"></TextView>
</LinearLayout>

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/linear4"
   android:orientation="horizontal"

  >
<ImageView android:id="@+id/ImageView03" android:layout_gravity="center" android:background="@drawable/up" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<TextView  android:paddingRight="69dip"  android:paddingLeft="10dip"  android:text="" android:id="@+id/txtindex2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textSize="12dip"></TextView>
<TextView  android:paddingRight="67dip"  android:text="" android:id="@+id/txtlast2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textSize="12dip"></TextView>
<TextView  android:text="" android:id="@+id/txtchange2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12dip" android:textColor="@color/green1"></TextView>

</LinearLayout>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/linear4"
    android:orientation="horizontal"

  >
<ImageView android:id="@+id/ImageView04" android:layout_gravity="center" android:background="@drawable/up" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<TextView  android:paddingRight="61dip" android:paddingLeft="10dip"   android:text="" android:id="@+id/txtindex3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textSize="12dip"></TextView>
<TextView  android:paddingRight="65dip"  android:text="" android:id="@+id/txtlast3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:textSize="12dip"></TextView>
<TextView  android:text="" android:id="@+id/txtchange3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12dip" android:textColor="@color/green1"></TextView>
</LinearLayout>

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
   android:id="@+id/linear1" android:layout_height="4dip"
     android:orientation="horizontal"
      >

<ImageView android:id="@+id/ImageView08" android:layout_gravity="center" android:background="@drawable/line" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageView>
</LinearLayout>

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="15dip"
  android:id="@+id/linear5"
  android:orientation="horizontal"

  >
<TextView android:text="Market data delayed at least 15 minutes " android:id="@+id/TextView16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12dip" android:textColor="@color/gray2"></TextView>
</LinearLayout>
</LinearLayout>
<------ finishing header-------->

<---------- adding footer----------->

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/imglinear"
  android:background="@color/white"
  android:layout_alignParentBottom="true"
  >
<ImageView android:id="@+id/ImageView15" android:src="@drawable/quest_i" android:layout_gravity="center"  android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</LinearLayout>

<--------------finishing footer------->

<------------ center point of screen--------->

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:background="@color/white"
  android:id="@+id/mainlinear3"
  android:layout_above="@+id/imglinear"
  android:layout_below="@+id/mainlinear2"
   >
  <ScrollView android:id="@+id/ScrollView01" 
     android:layout_width="wrap_content" android:layout_height="wrap_content">  
 <RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:background="@color/white"
  android:id="@+id/relative3">

  </RelativeLayout>
  </ScrollView>
</RelativeLayout>

<-----------center point finishing---------->

</RelativeLayout>

thanks

解决方案

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

    <!-- HEADER -->
    <include android:id="@+id/top_header"
        android:layout_alignParentTop="true" layout="@layout/layout_header" />


    <!-- FOOTER -->
    <LinearLayout android:id="@+id/bottom_menu"
        android:layout_width="fill_parent" android:layout_height="wrap_content"         
        android:orientation="vertical" android:layout_alignParentBottom="true">
        <!-- menu bar -->
        <include layout="@layout/layout_footer_menu" />
    </LinearLayout>

    <!-- MAIN PART -->
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_below="@id/top_header" android:layout_above="@id/bottom_menu"
        android:layout_weight="1"
        android:id="@+id/sub_content_view"
        android:paddingBottom="5sp" android:background="#EAEAEA">
    </LinearLayout>
</RelativeLayout>

It is better to set to MAIN PART both:

android:layout_below="@id/top_header" android:layout_above="@id/bottom_menu"

In your case content will be under the footer and scroll bar will be shown incorrect.

Also you need place footer in code above content - android want see ID's (@id/bottom_menu) if it wasn't define before.

这篇关于如何为android系统的线性布局中的页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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