android - 当孩子身高增加时,ScrollView 不滚动
问题描述
我有一个ScrollView
包含 2 个片段的。底部片段有 2 个EditText
视图。当我在任一 EditText 中输入多行文本时,屏幕上视图的整体高度要求自然会增加。但是,屏幕会切断由于多行文本输入而被推送的任何内容。ScrollView 在那一点上不滚动。
我在 SO 上尝试了一些建议的方法,例如不将 ScrollView 作为根视图或添加一个空视图作为滚动视图的最后一个孙子,但到目前为止它们都没有工作。这是我的 XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_height="wrap_content"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<fragment
android:id="@+id/fragment1"
android:name="com.example.omar.memegenerator.TopImageFragment"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:layout_marginBottom="18dp"
tools:layout="@layout/fragment_top_image" />
<fragment
android:id="@+id/fragment2"
android:name="com.example.omar.memegenerator.BottomControlsFragment"
android:layout_width="match_parent"
android:layout_height="134dp"
android:layout_below="@+id/fragment1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="34dp"
tools:layout="@layout/fragment_bottom_controls" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
解决方案
将其用于您的布局层次结构。我省略了一些属性,但包含的属性是让它工作的关键。
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical">
<fragment
android:id="@+id/fragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<fragment
android:id="@+id/fragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
推荐阅读
- php - 根据 if else 条件更新行值
- knockout.js - 如何禁用/启用嵌入在映射到淘汰赛可观察数组的表中的下拉列表
- android - 将 gradle 构建工具版本升级到 3.2.1 后,React Native 签名 apk 失败
- c++ - ANN 培训进度使用 FANN 重置每个新的培训课程
- javascript - 在javascript中按天比较两个日期
- jmeter - 如何处理jmeter中的特殊字符
- python - 堆叠数据框和排名
- javascript - 无法从 Javascript 中的“每个”函数返回布尔值
- jquery - 如何删除boostrap多选边框颜色
- ubuntu-18.04 - Ubuntu 如何修复 Xorg 会话?