ScrollView在Android Layout中不起作用

时间:2014-01-13 12:03:21

标签: android android-layout relativelayout android-xml

我为我的测试应用程序,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>

请帮帮我。

10 个答案:

答案 0 :(得分:0)

ScrollView您不需要TextViewTextView具有滚动属性。

尝试设置它并查看它是否有效。

答案 1 :(得分:0)

您可以使用this链接。在xml中使用scrollview的格式如下:

  <linearlayout>
      <scrollview>
        <linear>or <relativelayout>
        </linear layout>
      </scrollview>
  </linear layout>.

答案 2 :(得分:0)

  1. 将ScrollView的高度设置为38dp。
  2. 将TextView的大小设置为40sp。
  3. 然后你可以滚动TextView。

答案 3 :(得分:0)

滚动仅适用于由于尺寸较大或数量较多而无法在屏幕上看到其子部分的情况

答案 4 :(得分:0)

几周前我遇到了同样的问题,这是我的解决方案:

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:id="@+id/RelativeLayout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/textview" />
    </RelativeLayout>
</ScrollView>

但是如果TextView中没有“足够”的内容,则它不可滚动。只有当它超过你的屏幕kann“捕获”。

答案 5 :(得分:0)

重新导入项目后,一切正常。我不知道这是什么错误,但也许是因为日食有问题。

答案 6 :(得分:0)

您可以使用以下代码将TextView滚动,而不是将ScrollView用于TextView。

<TextView
    android:id="@+id/txtView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLines="5"
    android:scrollbars="vertical"
    android:textAppearance="?android:attr/textAppearanceSmall" />

在Java文件中使用此代码

txtView.setMovementMethod(new ScrollingMovementMethod());

希望这会有所帮助。

答案 7 :(得分:0)

Scrollable只是ScrollView之间的部分

所以如果你想滚动一切(而且我理解你这样做)你只需要改变顺序。 我也相信ScrollView需要布局并且有布局,所以你需要两个布局:一个内侧和一个外侧。虽然我不确定最后一句话 - 我只是开始学习东西

答案 8 :(得分:0)

它应该工作,请尝试

<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:padding_bottom = "10dp">
<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/textview" />
</ScrollView>

答案 9 :(得分:-1)

这是您的解决方案实现此代码并运行代码textview是可滚动的。

<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">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <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" />

    </RelativeLayout>
</ScrollView>

相关问题