Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the header and footer for linear layout in android

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

like image 750
mohan Avatar asked Jan 19 '11 07:01

mohan


People also ask

How do you align a linear layout?

To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .

What is the difference between linear and RelativeLayout in Android?

LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.

Can we use linear layout in ConstraintLayout?

You can create linear layouts now with ConstraintLayout by constraining the sides of each element with each other.

Which is better linear layout or relative layout?

LinearLayout is less used as compared to RelativeLayout. RelativeLayout is used more in applications. We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.


1 Answers

<?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.

like image 89
Vikas Patidar Avatar answered Oct 13 '22 11:10

Vikas Patidar