【发布时间】:2016-07-07 08:07:43
【问题描述】:
我正在为 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 inside ** 一切正常,但是当添加 ImageView 时,ScrollView 停止滚动。
我希望你能指出错误,希望没有提出愚蠢的问题。
非常感谢。
Android 工作室:2.1.2 JRE 1.8.0-b15
【问题讨论】:
-
你为什么在
ScrollView里面使用ScrollView。它的编程不好。 -
尝试使用 NestedScrollView developer.android.com/reference/android/support/v4/widget/… 。将 wrap_content 用于根 ScrollView 听起来也很奇怪。
-
发布所需输出的任何图像文件。
标签: java android xml scrollview