2

I face that situation multiple times creating application and I don't really know how to handle it properly. These are the elements I want:

  • Sticky view at the top (Toolbar or label...)
  • ScrollView containing an undefined number of elements (Lets say EditText)
  • Sticky button at the bottom that isn't part of the ScrollView.

I lost when it comes to set the height of the ScrollView since it might varies depending of the phone size... Should I embed them all in a LinearLayout? (Header, ScrollView and footer)

enter image description here

Jaythaking
  • 2,200
  • 4
  • 25
  • 67
  • I have implemented a library to do that. You can give it a try. Here is the link https://github.com/amarjain07/StickyScrollView – Amar Jain Mar 22 '17 at 07:08

1 Answers1

2

Maybe something like this:

<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"
    tools:context="com.example.wviana.testes.MainActivity">

<TextView
    android:id="@+id/top_sticky_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:textSize="28dp"
    android:text="I'm a TOP STICKY LABEL"/>

<TextView
    android:id="@+id/bottom_sticky_label"
    android:layout_alignParentBottom="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="28dp"
    android:text="I'm a BOTTOM STICKY LABEL"
    android:layout_weight="0"/>

<ScrollView
    android:id="@+id/my_scrool_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/top_sticky_label"
    android:layout_above="@id/bottom_sticky_label"
    >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="I'm a example EditText"/>

</ScrollView>

What would give you something like this:

enter image description here

wviana
  • 1,619
  • 2
  • 19
  • 47