android

Wednesday, 19 April 2017

How to add a footer view ,Header view and main content area in Android Layout ?

In this article we are going to see how you can create a simple Android Layout that includes a header part, a footer part and the content area. 


1. Create a new Android Project



We have to specify the Application Name, the Company Name and the Package name in the appropriate text fields and then click Next.





In this step,specify different factors our app will run,in our case we will use Phone and Tablets.




In this step select Empty activity and press Next.











In this step specify name of the activity class and layout file and click on finish.



2.Change the layout of the Main Activity

 Open app/res/layout/activity_main.xml file : and paste the following code
   filename :activity_main.xml





The idea is very simple first,we have put relative layout as a root layout ,
then as a header view we have put linear layout with attribute android:layout_alignParentTop=true 
and with id android:id=@+id/header.

Then for main content area we have put another linear layout with sttribute 
  android:layout_below=@+id/header and with attribute android:layout_above=@+id/footer.
You can also use Scrollview instead of linear layout for more flexible scrolling content.

For footer view we have put another linear layout with attribute 
android:layout_alignParentBottom="true" with id as 
android:id=@+id/footer

3. Code the Main Activity

         For this example we don’t have to change anything to the auto generated code so we can leave         it as it is.

4. Run the application

        This is how our Layout looks on the emulator: