この例に基づいてテキストをスクロールする TextView をカスタマイズするために、Android TextView から派生したクラスがあります:元のサンプル コード
私の問題は、スクロール中のテキストのサイズに応じて、テキストがさまざまな位置で切り捨てられることです。たとえば、長さが 90 文字のテキストは、テキスト サイズが 100 未満の場合は問題なくスクロールしますが、テキスト サイズが 240 に設定されている場合 (つまり、横向きモードで携帯電話の高さを埋めるため)、テキストは文字位置 83 で切り捨てられます。テキストのサイズが大きくなるほど切り捨てられます。
ある種のメモリ制限があるかのようです。
ScrollTextView scrolltext;
scrolltext.setTextSize(TypedValue.COMPLEX_UNIT_PX, xtextsize);
scrolltext.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
scrolltext.setSingleLine(true);
scrolltext.setEllipsize(null);
scrolltext.setMaxLines(1);
scrolltext.startScroll();
そしてクラスで
setHorizontallyScrolling(true);
mSlr = new Scroller(this.getContext(), new LinearInterpolator());
setScroller(mSlr);
int scrollingLen = calculateScrollingLen()
int duration = (new Double(((scrollstart.mRndDuration*10)/getWidth())*getText().length())).intValue();
setVisibility(VISIBLE);
mSlr.startScroll(mXPaused, 0, scrollingLen, 0, duration);
誰かが試して再現したい場合は、元のサンプル コードを使用して問題を再現できます。
テキストのサイズに応じて、テキストが異なる位置で切り捨てられる理由を知っている人はいますか?
私のレイアウト
<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.test.testing.ScrollTextView
android:id="@+id/scrolltext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:textSize="20sp"/>
</LinearLayout>
前もって感謝します
さらに: 別のフォントを使用する場合、同じテキスト サイズを使用すると、切り捨てが開始される位置が変わります。まだリソースの問題のように見えますが、どこでバッファを増やすべきですか?