tho*_*aus 24 android scroll android-linearlayout android-scrollview
我无法正确滚动ScrollView.它总是切断底部的内容,就像它是正常的LinearLayout一样.
我的代码
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout android:id="@+id/scroll_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true"
android:orientation="vertical" >
Run Code Online (Sandbox Code Playgroud)
当然,我已经尝试添加/删除"fillViewport"和"isScrollContainer"属性,它根本没有改变任何东西.
提前致谢.
tho*_*aus 26
答案:当用作XML布局的根元素时,ScrollView无法正常工作.它必须包含在LinearLayout中.
解决方案:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout android:id="@+id/scroll_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
小智 8
? 尝试了上述所有答案,但我的问题仍未解决。经过一些调试和更改后,我的问题得到了解决,即 ScrollView 正在滚动。
??修复是针对我的问题?
将 ScrollView 的高度更改为 0dp
android:layout_height="0dp"
将顶部和底部约束到父/各自的视图/元素
app:layout_constraintTop_toBottomOf="@+id/imageView4" app:layout_constraintBottom_toBottomOf="parent"
最终的 xml 看起来像这样
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/imageView4"
app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Loong content -->
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
Scroll View as Parent 没有问题。当我们向滚动视图的直接子级添加填充/边距时,我遇到了这样的问题。保持滚动视图的子级只有高度和宽度属性,它会正常工作。
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38508 次 |
| 最近记录: |