android - 为什么我不能在 textview android 中滚动?

标签 android textview android-scrollview

我是 android 的初学者,我写了一个简单的应用程序来在 android studio 的 textView 中显示一个简单的文本,但是当我在 textView 中写一个大文本时,textview 无法滚动,我的 xml 文件是:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
    android:layout_width="match_parent" android:layout_height="match_parent"
    tools:context=".MainActivity">
    <FrameLayout android:id="@+id/container" android:layout_width="match_parent"
            android:layout_height="match_parent" >
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Large Text"
            android:id="@+id/MAINLABEL"
            android:layout_gravity="center" />
        </FrameLayout>
</android.support.v4.widget.DrawerLayout>


发生了什么?

最佳答案

水平滚动:

<HorizontalScrollView android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:layout_width="40dp"
        android:layout_height="wrap_content"
        android:scrollHorizontally="true"
        android:text="Horizontal scroll view will work now"/>

</HorizontalScrollView>

垂直滚动:

实际上您不需要使用 ScrollView

只需设置

android:maxLines = "AN_INTEGER"

android:scrollbars = "vertical"

布局的 xml 文件中 TextView 的属性。

然后使用:

yourTextView.setMovementMethod(new ScrollingMovementMethod());

在您的代码中。

它会帮助你。谢谢。

关于android - 为什么我不能在 textview android 中滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31667984/

相关文章:

java - Android:从ArrayList中提取数据

android - ScrollView 在较低版本的 android 中无法正确显示其内容

android - ScrollView : check if a view is visible on screen or not

php - 访问 googleapis 失败

android - 列表适配器共享

android - 如何仅在确认对话框后翻转开关的选中状态?

android - 按钮监听器和 SimpleCursor 适配器

android - 彼此后面的两个 TextView,仅椭圆化第一个,第二个始终可见

android - 当没有文本可显示时,将 TextView 可见性设置为 GONE

ScrollView 自动滚动问题中的 Android ListView