【问题标题】:Android TextView ScrollableAndroid TextView 可滚动
【发布时间】:2014-07-15 10:10:23
【问题描述】:

我有一个大小为 16 个字符的 textView,如果它超过 16 个字符,我想让它可以滚动给用户以查看剩余的字符。 谁能帮帮我?

我试过这个链接Making TextView scrollable on 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"
    />

【问题讨论】:

  • 显示你的 TextView 布局
  • 我添加了 textview 请检查
  • 你可以使用这个:TextView.setMovementMethod(new ScrollingMovementMethod());使用 TextView.setselected(true); ...

标签: android listview android-intent textview


【解决方案1】:

在您的 XML 布局文件中:

<TextView
    android:id="@+id/message_scroll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:text="@string/lorem" />

在您的 Java 类文件中:

TextView tv = (TextView) rootView.findViewById(R.id.message_scroll);
tv.setMovementMethod(new ScrollingMovementMethod());

【讨论】:

  • 这太棒了,但我怎样才能垂直和水平滚动?
【解决方案2】:

将您的文本视图包装在滚动视图中:

<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>

【讨论】:

    【解决方案3】:

    您的 android:maxlength="16" 将 TextView 中可以放置的字符数限制为 16

    According to the developer site

    【讨论】:

      猜你喜欢
      • 2011-04-22
      • 2013-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 1970-01-01
      相关资源
      最近更新 更多