LinearLayout不随ScrollView滚动

5
我有一个LinearLayout,里面有许多动态添加的TextView。所谓“许多”,是指它们超出了屏幕底部。我想使用ScrollView使用户能够滚动到屏幕外并查看其余的TextView。目前,我的activity_main.xml文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<LinearLayout
    android:id="@+id/ll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="61dp"
    android:orientation="vertical" >
</LinearLayout>

</ScrollView>

非常感谢您的帮助!如果有任何问题,请随时联系我们。谢谢!


太好了!但是你具体遇到的问题是什么? - codeMagic
先使用match_parent属性设置LinearLayout的高度和宽度,然后展示你的代码,这样我们可以知道你尝试了什么。 - Pragnesh Ghoda シ
请使用match_parent来设置ScrollView的高度。 - Lei Guo
3个回答

1
尝试将 android:layout_width="wrap_content" 更改为 android:layout_width="match_parent"
<LinearLayout
    android:id="@+id/ll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="61dp"
    android:orientation="vertical" >
</LinearLayout>

</ScrollView>

把高度设置为match_parent。 - Kitesurfer

1
将您的代码更改如下!
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
    android:id="@+id/ll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="61dp"
    android:orientation="vertical" >

</LinearLayout>

</ScrollView>

注意:为了判断是否滚动,请在linearLayout中放置一些视图,如按钮,否则您将无法注意到屏幕滚动。


1

也可以像这样做。它有效运行。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollData"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" >



     <LinearLayout
        android:id="@+id/linearWhere"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:orientation="vertical"
        android:padding="5dp">

      </LinearLayout>
</ScrollView>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接