Sticky Header/Footer with ScrollView in between

核能气质少年 提交于 2020-01-06 08:21:10

问题


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)


回答1:


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:



来源:https://stackoverflow.com/questions/37886329/sticky-header-footer-with-scrollview-in-between

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!