我阅读了本主题中的一些主题,但是没有找到解决方案。我想在TextView上使用scrollHorizontally属性,但要从Java代码使用。
这是我尝试过的:
nameTextView = new TextView(context);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
nameTextView.setId(R.id.header_text_id);
nameTextView.setGravity(Gravity.CENTER | Gravity.LEFT);
nameTextView.setSingleLine();
nameTextView.setHorizontallyScrolling(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
nameTextView.setFocusableInTouchMode(true);
nameTextView.setMarqueeRepeatLimit(-1);
nameTextView.setFocusable(true);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/robotocondensed.ttf");
nameTextView.setTypeface(tf);
nameTextView.setTextColor(getResources().getColor(android.R.color.white));
我稍后再设定文字。文本不滚动,这可能是什么问题?
android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"
然后设置:
yourTextView.setMovementMethod(new ScrollingMovementMethod())
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句