【问题标题】:how to make scrollable horizontally and vertically the contents of a TextView如何使 TextView 的内容水平和垂直滚动
【发布时间】:2012-05-20 02:32:43
【问题描述】:

我想滚动在 TextView 中查看的结果,这是我的 xml:

<scroll>
<TextView
android:id="@+id/ris"
android:layout_width="wrap_content"
android:layout_height="229dp"
android:layout_weight="0.96"
android:textAppearance="?android:attr/textAppearanceMedium" />
</scroll>

但应用崩溃了。

【问题讨论】:

  • 您尝试采取什么措施来解决崩溃问题?崩溃消息说什么?

标签: android android-layout android-widget


【解决方案1】:

使用

<ScrollView> your View "</ScrollView">

而且必须只有一个子ScrollView。

【讨论】:

    【解决方案2】:

    将此添加到 TextView 的 XML 文件中

     android:scrollHorizontally="true"
     android:scrollVertically="true"
    

    【讨论】:

      【解决方案3】:

      TextView 中添加以下属性:

      android:maxLines = "1"
      android:scrollbars = "vertical"
      

      然后,在您实例化 TextView 后,添加以下行:

      mTextView.setMovementMethod(new ScrollingMovementMethod());
      

      【讨论】:

        【解决方案4】:
        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="19dp"
            android:layout_marginTop="24dp" >
        
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
        
                <TextView
                    android:id="@+id/tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/hello_world"
                    tools:context=".Tester" />
            </LinearLayout>
        </ScrollView>
        

        【讨论】:

        • 通过将 TextView 封装在 ScrollView 中,您将获得 ScrollView 的行为,例如垂直滚动。
        猜你喜欢
        • 2020-08-17
        • 1970-01-01
        • 1970-01-01
        • 2011-12-23
        • 2012-04-08
        • 1970-01-01
        • 1970-01-01
        • 2014-01-09
        • 1970-01-01
        相关资源
        最近更新 更多