我是 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/