2

Canvas.drawTextそのためのパラメーターがないものを使用しています。キャンバスにテキストを描画する幅が限られているので、スクロールする方法はありますか?

ありがとう。

4

2 に答える 2

1

解決策を得て、編集テキストの幅を計算し、テキストを測定します。テキストが広すぎる場合は、drawText パラメータで使用されるオフセット x 値を調整する実行可能なサイクルを開始します。

于 2012-08-30T09:45:53.480 に答える
-1

次に例を示します。

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 でマーキー テキストを参照

于 2012-08-29T13:39:27.200 に答える