Reputation: 21
How do I insert a scrollview into this, and still keep the header that I have on my app? Also, all of the tutorials seem to require you to switch to a LinearLayout, and the LinearLayout makes it hard for me to format all the buttons and text boxes that I need to include in the activity.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="washingtondeli.groupboxlunchesestimateandordering.CapitolhillActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Capitol Hill Picnic Box Lunch"
android:id="@+id/capitolhilltitle"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Upvotes: 0
Views: 72
Reputation: 733
You can use Relative Layout in a Scroll View, Here's a sample, for scroll view with relative layout with a fixed Header
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Header"
android:textColor="#ffffff"
android:textSize="22dp" />
<ScrollView
android:id="@+id/scrollView"
android:layout_below="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:fillViewport="true" >
<RelativeLayout
android:id="@+id/filt_top"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true" >
//your scrollable contents here
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Upvotes: 0
Reputation: 5626
Step 1: Make ScrollView your root layout
Step 2 Add a LinearLayout to your ScrollView
Remember, a ScrollView accepts only 1 Child
Then simply add your buttons inside your LinearLayout - which by the way could have other LinearLayouts to support different layout styles and then you have weights to position your items accordingly!
You can also look into other options. Oh, almost forgot this: read some tutorials on this to help you get started!
I hope this helps!
Upvotes: 3