为什么ScrollView即使有要显示的文本也不会滚动

时间:2016-07-07 08:07:44

标签: java android xml scrollview

我正在与 ScrollView 挣扎,并且真的不知道它有什么问题。

- 我的目标是制作一个带有图像和文本的可滚动片段(在每个图像下)。我已经添加了一些简单的图像,并试图在这些图像下为文本添加专用的ScrollView。

问题解释从这里开始: 当片段只有1个图像和1个ScrollView时,ScrollView工作正常,但是当我在下面再添加一个图像时,ScrollView就会冻结并且不再滚动。我的错误在哪里?

以下是代码:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true">
<LinearLayout
    android:id="@+id/LinearLayout_Parent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <ImageView
        android:id="@+id/top_image1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image1"
        android:adjustViewBounds="true"/>
        <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="100dp">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/rly_large"/>
        </ScrollView>
    //when ImageView is added ScrollView stops wotking
    **<ImageView
        android:id="@+id/top_image2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image2"/>**
</LinearLayout>

Whitout ImageView 里面**一切正常但是当添加ImageView时,ScrollView会停止滚动。

我希望你能指出这个错误,并希望没有提出一个愚蠢的问题。

非常感谢。

Android Stuido:2.1.2 JRE 1.8.0-b15

2 个答案:

答案 0 :(得分:0)

ScrollView置于另一个ScrollView内并不是一个好习惯。但是,您使用的代码在某些情况下可能会起作用。但是当你有多个元素时它可能会失败。在这种情况下,它可能无法识别gesture

但是,如果有帮助ScrollView Inside ScrollView,您可以尝试这个答案。当识别出对孩子的触摸时,它会禁用父ScrollView's触摸。如果有帮助的话,还可以查看此post

答案 1 :(得分:0)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ScrollView 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true">
<LinearLayout
    android:id="@+id/LinearLayout_Parent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <ImageView
        android:id="@+id/top_image1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image1"
        android:adjustViewBounds="true"/>
        <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="100dp">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/rly_large"/>
        </ScrollView>

    <ImageView
        android:id="@+id/top_image2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image2"/>
</LinearLayout>

您正在使用ScrollView作为根元素,但从不添加关闭标记。 (可能是复制粘贴问题)

此外,使用ScrollView作为根元素会导致我的体验出现问题,因此如果您将当前是根元素的ScrollView推入一个图层并将LinearLayout设置为根元素,则可以解决您的问题。

此外:

  

内部的Whitout ImageView **一切正常但是当添加ImageView时,ScrollView会停止滚动。

有点难以理解。哪两个停止滚动?

相关问题