[英]Android TextView horizontal scroll does not work
我阅读了本主题中的一些主题,但没有找到解决方案。 我想在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())
关于如何在android中制作水平可滚动textview的优秀文章,它的工作原理!
http://gabrielbl.com/2013/08/09/android-auto-horizontal-scrolling-marquee-textview/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.