【发布时间】:2014-01-13 12:03:20
【问题描述】:
我为我的测试应用程序设计了一个简单的布局,一个 TextView,然后是一个 ImageView 和一个 TextView。但是第二个 TextView 我希望它可以滚动(通过触摸)。
我在网上搜索并尝试了很多解决方案,但仍然无法成功。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:scrollbars="vertical"
tools:context=".MainActivity" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/title"
android:textSize="40sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:contentDescription="@string/ada_lovelace"
android:paddingTop="8dp"
android:src="@drawable/ada_lovelace" />
<ScrollView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:id="@+id/scroll1"
android:layout_below="@id/imageView1">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:text="@string/hello_world"
android:textSize="22sp" />
</ScrollView>
</RelativeLayout>
请帮帮我。
【问题讨论】:
-
只有在 textview 有更多元素需要滚动时才有效
-
参考这个链接,解决了我的问题....stackoverflow.com/questions/1748977/…..
-
使用 ListView 和简易适配器
-
请检查在第二个文本视图中添加更多内容
-
ScrollView 仅在内部布局超过 ScrollView 本身的大小时才有效。让我举个例子。假设您有一个具有 100dp 高度和 fill_parent 宽度的 ScrollView。它有一个 TextView,它有 150dp 的高度和 wrap_content 的宽度。由于 ScrollView 的高度为 100dp,因此您的 TextView 将可垂直滚动 50dp。所以在你的例子中,因为你的话,可能默认为“Hello world!”不超过您的 ScrollView 大小(注意您的 ScrollView 高度是屏幕大小),它不会滚动。
标签: android android-layout android-relativelayout android-xml