带有 ScrollView 的粘性页眉/页脚 [英] Sticky Header/Footer with ScrollView in between

查看:48
本文介绍了带有 ScrollView 的粘性页眉/页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建应用程序时多次遇到这种情况,但我真的不知道如何正确处理它.这些是我想要的元素:

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:

  • 顶部的粘性视图(工具栏或标签...)
  • ScrollView 包含未定义数量的元素(比如 EditText)
  • 底部不属于 ScrollView 的粘性按钮.

我在设置 ScrollView 的高度时输了,因为它可能会因手机尺寸而异......我应该将它们全部嵌入 LinearLayout 中吗?(页眉、滚动视图和页脚)

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)

推荐答案

也许是这样的:

<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:

这篇关于带有 ScrollView 的粘性页眉/页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆