Canvas.drawText
そのためのパラメーターがないものを使用しています。キャンバスにテキストを描画する幅が限られているので、スクロールする方法はありますか?
ありがとう。
Canvas.drawText
そのためのパラメーターがないものを使用しています。キャンバスにテキストを描画する幅が限られているので、スクロールする方法はありますか?
ありがとう。
解決策を得て、編集テキストの幅を計算し、テキストを測定します。テキストが広すぎる場合は、drawText パラメータで使用されるオフセット x 値を調整する実行可能なサイクルを開始します。
次に例を示します。
public class TextViewMarquee extends Activity {
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) this.findViewById(R.id.tv);
tv.setSelected(true); // Set focus to the textview
}
}
テキストビューを含む xml ファイル:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/mywidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:lines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="Simple application that shows how to use marquee, with a long text" />
</RelativeLayout>
注- これは、android:singleLine="true" が指定されている場合にのみ機能します 。Android でマーキー テキストを参照