Search code examples
androidandroid-layoutscrollviewandroid-scrollview

Can we lock top and bottom view in a layout while we are using scrollview


I am implementing a data entry screen with few fields.In ScrollView for better view(Visibility) in small devices. In that activity i want to LOCK both Heading(textView1) and bottom Layout(myButtonsLayout).I am able to lock conform button.But unable to lock heading.Please help me to solve my issue.

Means i want to scroll my layout(ScrollView) without moving Header and Footer

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/bluebutton"
        android:gravity="center"
        android:paddingTop="10dp"
        android:text="Default Details"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/white"
        android:textSize="30dp"
        android:textStyle="bold" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" 
    android:background="#2E9AFE"
    android:layout_above="@+id/myButtonsLayout">


    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <TextView
        android:id="@+id/tvtv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:paddingTop="10dp"
        android:text="Default recipient Mobile no:"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/white"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/etDefMobNo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:hint="Def mobile no"
        android:inputType="phone" >

    </EditText>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        android:text="Default SMS content:"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/white"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/etDefMsg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView3"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:hint="Def Message content"
        android:inputType="textMultiLine"
        android:lines="6" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        android:text="Default recipient email id:"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/white"

        android:textStyle="bold" />

    <EditText
        android:id="@+id/etDefEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/etDefMsg"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView4"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:hint="Def Email"
        android:inputType="textEmailAddress" />
</LinearLayout>
</ScrollView>
    <LinearLayout 
    android:id="@+id/myButtonsLayout"
    android:layout_width="wrap_content"
    android:layout_height="100dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:background="#2E9AFE" >

        <Button
            android:id="@+id/bsave1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/etDefEmail"
            android:layout_gravity="left|center"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="10dp"
            android:layout_weight="50"
            android:background="@drawable/blackbutton"
            android:text="Save"
            android:textColor="@android:color/white"
            android:textSize="24dp"
            android:textStyle="bold" />

    <Button
        android:id="@+id/bReset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/etDefEmail"
        android:layout_gravity="right|center"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="20dp"
        android:layout_toRightOf="@+id/textView3"
        android:layout_weight="50"
        android:background="@drawable/blackbutton"
        android:text="Reset"
        android:textColor="@android:color/white"
        android:textSize="24dp"
        android:textStyle="bold" />

</LinearLayout>

</RelativeLayout>

Solution

  • It looks like android:layout_alignParentTop="true" is causing your scrollview to be placed on top of your header.

    Try this instead:

    android:layout_below="@id/textView1"