AndroidStudio ケース - マーキー

 シンプルなマーキー、TextView を使用するだけです。

【結果を示す】

[activity_main.xml コード]

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我最美最美最美最美哈哈哈我是天下第一美丽的"
        android:textSize="40dp"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="true"
/>

【コード解説】

android:singleLine: テキストを 1 行で表示する

android:ellipsize (singleLine で使用)

android:ellipsize = "end" 末尾の省略記号

android:ellipsize = "start" 先頭に省略記号

android:ellipsize = "middle" 真ん中の省略記号

android:ellipsize = "マーキー" マーキー

android:ellipsize = "none" 省略記号がなく、文字数が多すぎると表示が不完全になります

 android:marqueeRepeatLimit: マーキーがスクロールする回数を設定します

TextView をフォーカスする

android:focusable="true"
android:focusableInTouchMode="true"

【知らせ】

  • TextView は 1 行で表示する必要があります。つまり、コンテンツは TextView のサイズを超える必要があります。
  • TextView はスクロールするためにフォーカスを取得する必要があります

おすすめ

転載: blog.csdn.net/m0_52177571/article/details/127445531