Android TextView Scrollable

Str*_*ing 4 android listview textview android-intent

我有一个textView,其大小为16个字符,如果超过16个字符,我想让它可以滚动到用户查看剩余的字符.任何人都可以帮助我吗?

我试过这个链接让TextView可以在Android上滚动

但没有结果?

我的TextView布局:

<TextView  
    android:id="@+id/tv1"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:maxLength="16"
       android:scrollbars = "vertical"
       android:ellipsize="end"
    android:text="fdgdddhhhdhd"
    />
Run Code Online (Sandbox Code Playgroud)

小智 25

在您的XML布局文件中:

<TextView
    android:id="@+id/message_scroll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:text="@string/lorem" />
Run Code Online (Sandbox Code Playgroud)

在您的Java类文件中:

TextView tv = (TextView) rootView.findViewById(R.id.message_scroll);
tv.setMovementMethod(new ScrollingMovementMethod());
Run Code Online (Sandbox Code Playgroud)


小智 5

将您的textview包装在scrollview中:

<ScrollView
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" >
        <TextView  
            android:id="@+id/tv1"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:maxLength="16"
            android:scrollbars = "vertical"
            android:ellipsize="end"
            android:text="fdgdddhhhdhd" />
</ScrollView>
Run Code Online (Sandbox Code Playgroud)