粘性 Header/Footer,中间有 ScrollView
Sticky Header/Footer with ScrollView in between
我在创建应用程序时多次遇到这种情况,但我真的不知道如何正确处理它。这些是我想要的元素:
- 顶部的粘性视图(工具栏或标签...)
- ScrollView 包含未定义数量的元素(比方说 EditText)
- 底部的粘滞按钮不属于 ScrollView。
我在设置 ScrollView 的高度时迷路了,因为它可能会根据 phone 大小而变化...我应该将它们全部嵌入到 LinearLayout 中吗? (页眉、滚动视图和页脚)
也许是这样的:
<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>
什么会给你这样的东西:
我在创建应用程序时多次遇到这种情况,但我真的不知道如何正确处理它。这些是我想要的元素:
- 顶部的粘性视图(工具栏或标签...)
- ScrollView 包含未定义数量的元素(比方说 EditText)
- 底部的粘滞按钮不属于 ScrollView。
我在设置 ScrollView 的高度时迷路了,因为它可能会根据 phone 大小而变化...我应该将它们全部嵌入到 LinearLayout 中吗? (页眉、滚动视图和页脚)
也许是这样的:
<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>
什么会给你这样的东西: