In my application I have created a Relative layout containing 5 buttons and now I want to use the same layout in other layouts as a background. I am trying the code android:background+"@layout/dashboard" but eclipse is showing me an error. I want to show that layout as Parent Bottom so that I can implement a scroll view and can call all the elements except the dashboard. Please help me in letting me know that:
- How can I add another layout as a background
- How can I set that layout to alignParentBottom
- how can I modify the scrollView so that dashboard stays static and the rest of the elements can scroll..
Code for dashboard.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:text="Home" />
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/b1"
android:layout_alignParentBottom="true"
android:text="Explore" />
<Button
android:id="@+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="MIC" />
<Button
android:id="@+id/b4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/b5"
android:layout_alignParentBottom="true"
android:text="Msngr" />
<Button
android:id="@+id/b5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:text="Profile" />
</RelativeLayout>
Code for showdashboard.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@layout/dashboard" >
</LinearLayout>
The Error that I am Getting is:
Failed to parse file C:\Users\%username%\Documents\eclipse\CustomList\res\layout\dashboard.xml
Exception details are logged in Window > Show View > Error Log
Please help..
Since you would like a static view pf buttons at the bottom of the page, you can wrap those buttons in a linear layout and the put the rest inside a scroll view.
you can change the size of bottom layout/scrollview by adjusting the layout weights.
If you want to use the same layout for more than one activity, then make separate linear layouts (or others if you prefer) and then you can add them to the scrollView in your activities.
where s_view is the id of the scroll view and the component view is the target layout.