【问题标题】:horizontal textView autoscrolling doesn't work (singleLines deprecated)水平 textView 自动滚动不起作用(不推荐使用单行)
【发布时间】:2016-12-05 21:53:05
【问题描述】:

目的是让任何文本在文本视图中自动水平滚动。我试图找到方法,但最好的结果是:xml

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/text_album_artist_title"
        android:gravity="center"
        android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget"
        android:maxLines="1"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit ="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:scrollHorizontally="true"
        />

代码

textViewSongTitleAlbumArtist = (TextView) v.findViewById(R.id.text_album_artist_title);
    textViewSongTitleAlbumArtist.setSelected(true);

它可以工作,文本滚动并且一切正常,但是当我尝试更改文本视图时,它停止工作。 xml相同,代码不同:

textViewSongTitleAlbumArtist = (TextView) v.findViewById(R.id.text_album_artist_title);
    textViewSongTitleAlbumArtist.setSelected(true);
    textViewSongTitleAlbumArtist.setText(musicSrv.getCurrentPlayingSong().mTitle + " " +
            musicSrv.getCurrentPlayingSong().mArtist + " " + musicSrv.getCurrentPlayingSong().mAlbum);

所以我想让我设置到 textview 中的任何文本水平、自动和无限次滚动。

【问题讨论】:

  • 尝试在 标签内使用`android:scrollbars="horizo​​ntal"`属性。
  • 试过了,没有成功

标签: android


【解决方案1】:

使用代码

textViewSongTitleAlbumArtist.setSelected(true);

在此代码下方

textViewSongTitleAlbumArtist.setText(musicSrv.getCurrentPlayingSong().mTitle + " " + musicSrv.getCurrentPlayingSong().mArtist + " " + musicSrv.getCurrentPlayingSong().mAlbum);

【讨论】:

  • 可能是因为文本完全适合可用空间。只有在没有空间显示文本时才会滚动。
  • no不行,我加了很长的字符串,不行
  • android:singleLine="true" 尝试将其添加到 textview xml 一次,删除 android:maxLines="1" 行
  • 它已被弃用,但我会尝试
  • 是的,但是 maxLines 不像 singleLine 那样工作。让我知道它是否有效
猜你喜欢
  • 2013-11-11
  • 1970-01-01
  • 2017-01-07
  • 2013-06-29
  • 2012-08-13
  • 1970-01-01
  • 2011-07-25
  • 1970-01-01
  • 2019-01-06
相关资源
最近更新 更多