0% found this document useful (0 votes)
28 views9 pages

Android Header and Footer Layout Example - Java Code Geeks

sdfvgsdv bfdbf dfb fd

Uploaded by

AmanKumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views9 pages

Android Header and Footer Layout Example - Java Code Geeks

sdfvgsdv bfdbf dfb fd

Uploaded by

AmanKumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

12/30/2014

Home

AndroidHeaderandFooterlayoutexample|JavaCodeGeeks
Tutorials

Java

Android

JoinUs

About

Resources

JVMLanguages

JobBoard

Examples

SoftwareDevelopment

Agile

Whitepapers

DevOps

Academy

Communications

Career

Misc

Searchthissite...

MetaJCG

Youarehere:Home AndroidCore AndroidHeaderandFooterlayoutexample

December30,20145:51pm

AboutNikosMaravitsas
NikoshasgraduatedfromtheDepartmentofInformaticsandTelecommunicationsofTheNationalandKapodistrianUniversity
[Link],hismaininterestsaresystemssecurity,parallelsystems,artificialintelligence,operatingsystems,system
programming,telecommunications,webapplications,humanmachineinteractionandmobiledevelopment.

Newsletter

66258insidersarealreadyenjoyingweekly

AndroidHeaderandFooterlayoutexample

updatesandcomplimentarywhitepapers!

Jointhemnowtogainexclusiveaccess

byNikosMaravitsasonOctober1st,2013 | Filedin:AndroidCore

tothelatestnewsintheJavaworld,aswellas

InthisarticlewearegoingtoseehowyoucancreateasimpleAndroidLayoutthatincludesaheaderpart,afooterpartandthecontent

insightsaboutAndroid,Scala,Groovyandother

[Link]

relatedtechnologies.

fromoneanother,soyoucanuseitanywhereinyourapplication,[Link]
example.
Forthistutorial,wewillusethefollowingtoolsinaWindows64bitplatform:
1. JDK1.7

Emailaddress:
Youremailaddress
Signup

2. Eclipse4.3Kepler
3. AndroidSKD4.3

JoinUs

JoinUs

[Link]

With 819,138 monthly


uniquevisitorsandover 500
authorsweareplacedamong

OpenEclipseIDEandgotoFile>New>Project>Android>AndroidApplicationProject.

thetopJavarelatedsites
[Link]
thelookoutforpartnerswe
[Link]
Ifyouhaveablogwithuniqueandinteresting
contentthenyoushouldcheckoutourJCG
[Link]
forJavaCodeGeeksandhoneyourwritingskills!
RecentJobs

SoftwareTester
Springfield,VA

EntryLevelSoftwareDeveloper:Atlana,GAJob
Atlanta,GA

TechnicalBusinessAnalyst/ApplicationSupport
NewYork,NY

JavaWebApplicationDeveloperSr.
ThousandOaks,CA

LeadApplicationsDeveloper
NewBritain,CT

ViewAll

YouhavetospecifytheApplicationName,theProjectNameandthePackagenameintheappropriatetextfieldsandthenclickNext.

[Link]

1/9

12/30/2014

AndroidHeaderandFooterlayoutexample|JavaCodeGeeks

InthenextwindowmakesuretheCreateactivityoptionisselectedinordertocreateanewactivityforyourproject,andclickNext.
Thisisoptionalasyoucancreateanewactivityaftercreatingtheproject,butyoucandoitallinonestep.

SelectBlankActivityandclickNext.

[Link]
[Link] res/layout/[Link] [Link],clickFinish.

[Link]
Open res/layout/[Link] file:

[Link]

2/9

12/30/2014

AndroidHeaderandFooterlayoutexample|JavaCodeGeeks

Andpastethefollowingcode:
[Link]:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

<?xmlversion="1.0"encoding="utf8"?>
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">

<!Headeralignedtotop>

<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#FC9"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="FixedHeader"
android:textColor="#000"
android:textSize="20sp"/>
</RelativeLayout>

<!Footeralignedtobottom>

<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FC0"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="FixedFooter"
android:textColor="#000"
android:textSize="20sp"/>
</RelativeLayout>

<!Contentbelowheaderandabovefooter>

<RelativeLayout
android:id="@+id/content"
android:layout_width="fill_parent"

50
51
52
53
54
55
56
57
58
59
60
61
62
63

android:layout_height="fill_parent"
android:layout_above="@id/footer"
android:layout_below="@id/header"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Content"
android:textColor="#33E"
android:textSize="20sp"/>
</RelativeLayout>

</RelativeLayout>

[Link] RelativeLayouts ,onealignedatthetopofthescreen,


using android:layout_alignParentTop="true" property,andonealignedatthebottomofthescreen
using android:layout_alignParentBottom="true" [Link] RelativeLayout betweenthesetwoview
using android:layout_above="@id/footer" and android:layout_below="@id/header" .Thesepropertieswillplace
our RelativeLayout withid content ,representingthecontentareaofourLayout,abovetheelementwithid footer andbellowthe
elementwithid header .
[Link]

3/9

12/30/2014

AndroidHeaderandFooterlayoutexample|JavaCodeGeeks

YoucanpreviewthelayoutyouvecreatedintheGraphicalLayouteditor:

[Link]
UsethePackageExplorertonavigatetotheJavafileoftheActivityyouvecreated:

Forthisexampleyoudonthavetochangeanythingtotheautogeneratedcodesoyoucanleaveitasitis.
[Link]:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21

[Link];

[Link];
[Link];
[Link];

publicclassMainActivityextendsActivity{

@Override
protectedvoidonCreate(BundlesavedInstanceState){
[Link](savedInstanceState);
setContentView([Link]);
}

@Override
publicbooleanonCreateOptionsMenu(Menumenu){
//Inflatethemenu;thisaddsitemstotheactionbarifitispresent.
getMenuInflater().inflate([Link],menu);
returntrue;
}
}

[Link]
ThisishowourLayoutlooksontheemulator:

[Link]

4/9

12/30/2014

AndroidHeaderandFooterlayoutexample|JavaCodeGeeks

androidemulator

MakingyourLayoutflexible
[Link]
[Link],moreimportantlyyoumaywanttomakethislayoutreusabletoyourotheractivities,eachone
havingtheirowncontentstodisplayandmaybetheirownheadersandfooters.
Toachievethat,[Link]
[Link],everyactivitythathasitsowncontentcanincludetheheaderandthefooterin
theirownLayouts.
TocreateanewXMLLayoutfilecontainingtheitemsyouwanttofillyour ScrollView [Link],gotothe
PackageExplorerandfind /res/layout [Link]>New>Other>Android>AndroidXMLLayoutfile:
newlayoutfile

Putanameforyournewlayoutfile,andselectRelativeLayoutfromthelist(althoughthisisnotabsolutelynecessary)andclickFinish:

[Link]

5/9

12/30/2014

AndroidHeaderandFooterlayoutexample|JavaCodeGeeks

headerxml

Youneedtocreate [Link] also.


So,afterthecreationofthenewlayoutXMLfiles,thisisthenewProjectStructure:
newprojectstructure

[Link]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16

<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FC0"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="FixedFooter"
android:textColor="#000"
android:textSize="20sp"/>
</RelativeLayout>

[Link]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17

<?xmlversion="1.0"encoding="utf8"?>
<RelativeLayoutxmlns:android="[Link]
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FC0"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="FixedFooter"
android:textColor="#000"
android:textSize="20sp"/>

[Link]

6/9

12/30/2014

18

AndroidHeaderandFooterlayoutexample|JavaCodeGeeks

</RelativeLayout>

[Link]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

<?xmlversion="1.0"encoding="utf8"?>
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">

<!Headeralignedtotop>

<includelayout="@layout/header"/>

<!Footeralignedtobottom>

<includelayout="@layout/footer"/>

<!Contentbelowheaderandabovefooter>

<RelativeLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/footer"
android:layout_below="@id/header"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Content"
android:textColor="#33E"
android:textSize="20sp"/>
</RelativeLayout>

</RelativeLayout>

[Link],youcaninclude
[Link] <includelayout="@layout/header"/> toincludetheheaderand <include
layout="@layout/footer"/> ( header and footer mustcorrespondtothenamesyougavetotherespectiveXMLLayoutfiles)

Runtheapplication
ThisishowourLayoutlooksontheemulator:
androidemulator

DownloadEclipseProject
[Link]
tutorial:[Link]

DoyouwanttoknowhowtodevelopyourskillsettobecomeaJavaRockstar?
SubscribetoournewslettertostartRockingrightnow!
TogetyoustartedwegiveyoutwoofourbestsellingeBooksforFREE!

JPAMiniBook
LearnhowtoleveragethepowerofJPAinordertocreaterobustandflexibleJavaapplications.
WiththisMiniBook,youwillgetintroducedtoJPAandsmoothlytransitiontomoreadvanced
concepts.

JVMTroubleshootingGuide
[Link]
withthisadvancedguide!

Emailaddress:

Youremailaddress

[Link]

Signup!

7/9

12/30/2014

AndroidHeaderandFooterlayoutexample|JavaCodeGeeks

5Responsesto"AndroidHeaderandFooterlayoutexample"

thinagaran
November6th,2013at8:29pm

Onanunrelatednote,didyoucompileusingJDK1.7
Reply

Joielechong
March27th,2014at7:00am

Thanksforthecode.:D
Reply

SohailMalik
April2nd,2014at11:03pm

[Link],stayblessed.
Reply

JoanNbusoba
May13th,2014at12:24pm

[Link]!!
Reply

sarwesh
September4th,2014at4:22pm

Thanksforcode
Reply

LeaveaReply
Name(Required)
Mail(willnotbepublished)(Required)
Website

+1=five
[Link].
Signmeupforthenewsletter!
SubmitComment

KnowledgeBase

Academy

Partners

Mkyong

Examples
Resources
Tutorials
Whitepapers

TheCodeGeeksNetwork

HallOfFame

AboutJavaCodeGeeks

AndroidFullApplicationTutorialseries

JCGs(JavaCodeGeeks)isanindependentonlinecommunityfocusedon

GWT2Spring3JPA2Hibernate3.5Tutorial

creatingtheultimateJavatoJavadevelopersresourcecentertargetedatthe
technicalarchitect,technicalteamlead(seniordeveloper),projectmanagerand

AdvantagesandDisadvantagesofCloud

[Link],SOA,AgileandTelecom

JavaCodeGeeks

ComputingCloudcomputingprosandcons

communitieswithdailynewswrittenbydomainexperts,articles,tutorials,

.NETCodeGeeks

AndroidGoogleMapsTutorial

reviews,announcements,codesnippetsandopensourceprojects.

WebCodeGeeks

AndroidLocationBasedServicesApplication
GPSlocation
11OnlineLearningwebsitesthatyoushould
checkout
JavaBestPracticesVectorvsArrayListvs

[Link]

8/9

12/30/2014

AndroidHeaderandFooterlayoutexample|JavaCodeGeeks

HashSet
AndroidJSONParsingwithGsonTutorial
AndroidQuickPreferencesTutorial
DifferencebetweenComparatorand
ComparableinJava

JavaCodeGeeksandallcontentcopyright20102014,ExelixisMediaLtd|TermsofUse|PrivacyPolicy|Contact
AlltrademarksandregisteredtrademarksappearingonJavaCodeGeeksarethepropertyoftheirrespectiveowners.
JavaisatrademarkorregisteredtrademarkofOracleCorporationintheUnitedStatesandothercountries.
JavaCodeGeeksisnotconnectedtoOracleCorporationandisnotsponsoredbyOracleCorporation.

[Link]

9/9

Common questions

Powered by AI

Hardcoding layout elements restricts the reusability and scalability of the code, making it difficult to update or modify components across different activities. In contrast, using dynamic inclusion techniques like <include> tags enables separation of concerns, allowing for easier updates and consistency across the app, ultimately enhancing maintainability .

Transitioning from a hardcoded layout to a dynamic model can introduce challenges such as increased complexity in managing layout dependencies and ensuring consistent behavior across different parts of the app. These can be resolved by adopting best practices in modular design, utilizing layout inflation techniques, and effectively managing resource identifiers to ensure proper linkage between components .

Including header and footer layouts enhances the user experience by providing consistent navigation and contextual information, making it easier for users to understand the app structure and access key functions. It also contributes to a more organized and visually appealing interface .

Modularity in Android layout design allows developers to create isolated, reusable components, reducing code duplication and facilitating easier maintenance and updates. This efficient development method supports scalability and adaptability, ensuring apps can evolve without extensive rewrites .

Creating separate layout files for headers and footers in Android development promotes reusability and modularity. It allows developers to include these components in various activities without rewriting code, making the layout structure more flexible and maintainable .

Using layout XML files allows developers to define UI components in a structured and declarative manner, separating design from logic. This separation simplifies the development process, making it easier to manage and update the UI without affecting the application's codebase .

Eclipse IDE offers a robust environment for Android development, providing tools like code editors, layout designers, and emulator integration that facilitate app creation and testing. However, with the rise of Android Studio, developers now have access to improved features and more efficient workflows, potentially overshadowing the benefits of using Eclipse .

The 'android:layout_above' and 'android:layout_below' properties are crucial for organizing layouts by allowing developers to position elements relative to each other. This assists in creating intuitive and responsive interfaces, ensuring that UI components are displayed in a logical and user-friendly order .

Java Code Geeks offers comprehensive resources including tutorials, code snippets, and articles that can be beneficial for novice developers to learn Android development. However, the content may assume a certain level of prior knowledge, which might require beginners to supplement their learning with foundational resources .

RelativeLayout allows for versatile positioning of UI components by enabling properties that define the alignment of child views relative to one another or within the parent. This flexibility makes it easier to create adaptive layouts that adjust dynamically to different screen sizes and orientations .

You might also like