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