TextView 可在 ScrollView 中滚动 [英] TextView scrollable in ScrollView

查看:49
本文介绍了TextView 可在 ScrollView 中滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在活动的顶部节点有一个 ScrollView,里面有几个 TextView.我想要其中一些(2 个中的 1 个)TextView 可以自己滚动.他们每行都做超过 5 行,但我希望访问者只看到 5 行,并且必须滚动才能观看完整的文本.但是我所做的...不起作用:

I have a ScrollView at the top node of an activity, with several TextView inside. I want some of these (1 out of 2) TextView scrollable themselves. They are doing more than 5 lines each but I want visitor see only 5 lines and have to scroll to watch the complete text. But what I do... doesn't work:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
         <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textStyle="italic"
            android:text = "Blabla"/>


         <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/blanc"
            android:maxLines="5"
            android:scrollbars="vertical"
            android:text="Blablabla1\nBlablabla2\nBlablabla3\nBlablabla4\nBlablabla5\nBlablabla6\nBlablabla7\nBlablabla8\n"/>

         <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textStyle="italic"
            android:text = "Blabla"/>


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/blanc"
            android:maxLines="5"
            android:scrollbars="vertical"
            android:text="Blablabla1\nBlablabla2\nBlablabla3\nBlablabla4\nBlablabla5\nBlablabla6\nBlablabla7\nBlablabla8\n"/>

         <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textStyle="italic"
            android:text = "Blabla"/>


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/blanc"
            android:maxLines="5"
            android:scrollbars="vertical"
            android:text="Blablabla1\nBlablabla2\nBlablabla3\nBlablabla4\nBlablabla5\nBlablabla6\nBlablabla7\nBlablabla8\n"/>
    </LinearLayout>

</ScrollView>

这样做后,TextViews 放置了 5 行,但它们不可滚动.

Doing that, TextViews put 5 first lines, but they are not scrollable.

我做错了什么?

推荐答案

ScrollView 与否无关紧要.解决方案是在您的 Java 代码中做更多的事情:

ScrollView or no doesn't matter. The solution is to do that more in you Java Code:

textviewtv.setMovementMethod(new ScrollingMovementMethod());

感谢:Android:带有垂直滚动文本的Textview

这篇关于TextView 可在 ScrollView 中滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆