2016年12月5日月曜日

テキストのスクロール

こんにちは。

今日は、簡単ですが、テキストビューのスクロールについて書きます。

お買い物電卓の計算結果の下の計算式で使用している横スクロールです。
activity.xmlを以下のようにしました。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<HorizontalScrollView
    android:id="@+id/scrollView"
    ads:layout_columnSpan="4"
    ads:layout_column="0"
    ads:layout_columnWeight="4"
    ads:layout_row="4"
    android:fillViewport="true">
    <TextView
        android:text=""
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textViewHistory"
        android:gravity="center_vertical|end"
        android:textSize="@dimen/other_text_size"
        android:maxLines="1"
        android:background="@color/colorTextBackground"/>
</HorizontalScrollView>
HorizontalScrollViewの中にTextViewを置きます。これだけで表示文字数が多くなると横スクロールできるようになります。


あるタイミングで、自動的に表示位置を調整したい場合は、以下を実行します。

1
2
3
4
5
scrollView.post(new Runnable() {
    public void run() {
        scrollView.fullScroll(FOCUS_RIGHT);
    }
});
お買い物電卓の計算式の場合は、右端にスクロールするようにしました。

0 件のコメント:

コメントを投稿