12

親ビューを使用して、TextView で水平スクロールを正しく行うことをお勧めしました。

<HorizontalScrollView android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:scrollHorizontally="true"
        android:gravity="center|right"
        android:text="123456789"/>

</HorizontalScrollView>

水平スクロールは正常に機能しますが、コンテンツが親の幅よりも長くなると右にオーバーフローします。

-------
|123456|7
-------

しかし、私は数字を保持するテキストビューに取り組んでおり、数字は一般的に右に配置されるため、テキストビューを反対側にオーバーフローさせる必要があります。(文字列の先頭を表示するには、左にスクロールする必要があります)。

 ------
1|4567|
 ------

gravity="right" と widths の複数の組み合わせを試しましたが、うまくいきません。テキストを右揃えにして左にオーバーフローさせるにはどうすればよいですか?


編集:

ユーザーが次のように入力したときにこれを試しました:

calc.setText( newNumber );
HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.hsv);
hsv.scrollTo(hsv.getRight(), hsv.getTop());

これは、ユーザーが数字を入力するたびに右にスクロールしますが、最新の数字は常に画面から除外されます (スクロールして数字を追加したようなものです)。

4

7 に答える 7

4

これに触発され

Horizo​​ntalScrollView から派生した独自のクラスを作成できます

public class RightAlignedHorizontalScrollView extends HorizontalScrollView {
    public RightAlignedHorizontalScrollView(Context context) {
        super(context);
    }

    public RightAlignedHorizontalScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RightAlignedHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
        scrollTo(getChildAt(0).getMeasuredWidth(), 0);
    }
}

そこに完全な単純なプロジェクトを投稿しました

于 2013-02-07T21:06:19.527 に答える
1
<HorizontalScrollView 
    android:id="@+id/hsv1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:scrollHorizontally="true"
        android:gravity="center|right"
        android:text="123456789"/>

</HorizontalScrollView>    

Horizo​​ntalScrollView に id を追加しました

HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.hsv1);
hsv.scrollTo(hsv.getRight(), hsv.getTop());

これは、その場で作成したため、テストされていません。それがどうなるか教えてください。

于 2012-12-31T19:46:18.700 に答える
1

android:fillViewport="true"スクロールビューにはプロパティを使用する必要があると思います
Check This & This

チュートリアルを進める

   <ScrollView 
        android:fillViewport="true"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/scrollView"/>

疑問: scroll-view のコンテナ レイアウトはどこにありますか??

于 2013-02-06T08:57:20.287 に答える
0

これを試してみてください。これは適切に機能し、スレッド間をジャンプするときに遅延が発生することはありません

hor = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
    hor.postDelayed(new Runnable() {
        public void run() {
            hor.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
        }
    }, 1L);
于 2015-10-18T06:44:55.867 に答える
0

ellipsize パラメータをテキストビューに割り当ててみましたか?

android:singleLine="true"
android:ellipsize="start"

これで問題が解決することを願っています。

オーバーフローしていないときのテキストの重力を設定するには、設定してみてください

android:gravity="center_vertical|right"
于 2013-02-07T11:28:10.493 に答える