1
我正在寻找一种让TextView滚动的方法。我发现了这个问题的答案,使用特定的XML属性涉及...滚动TextView重绘问题
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/textview" android:text="The long text, which no way have chance to fit within screen's width"
android:maxLines="1"
android:scrollHorizontally="true" />
</LinearLayout>
...一小片的源代码
package spk.sketchbook;
import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.Gravity;
import android.widget.TextView;
public class SketchbookMain extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView)findViewById(R.id.textview);
textView.setMovementMethod(ScrollingMovementMethod.getInstance());
}
}
...一切作品般的魅力,但直到一个试图对齐文本中的TextView向右......
android:gravity="right|center_vertical"
...观察,直到用户试图滚动文本,它是无形的(可能滚出风景)。
不幸的是,这正是我需要做的(使右对齐的TextView可滚动)。
有什么想法吗?
我终于改变了TextView的进入EditText上,问题就解决了。我想,尽管如此,你的解决方案也会起作用。然而,这是我发现的第三个Android库错误,这使得Android开发非常恼人。感谢帮助。 – Spook 2011-06-13 11:25:50
@Spook感谢您使用'EditText'的想法,但它可以帮助我使用'setMaxLines(1)',不要使用'setSingleLine' – BNK 2016-06-02 09:25:00