编写长文本在Android屏幕上显示以便屏幕滚动显示
答
这将工作,诀窍是让你想滚动内滚动视图。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/text" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
+0
thanx这是最简单的 – dashh 2012-07-21 13:35:03
答
文本切断意味着你遇到了什么问题。尝试下面的代码。它的工作原理.....
使用XML代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="HERE I TOOK NEARLY 3-4 PAGES OF DOCUMENT. IT WORKED" />
</ScrollView>
如果要创建动态是指,按照这个代码: main.java:
oncreate()
{
ScrollView sv=(ScrollView)findViewById(R.id.scrollView1);
TextView tv=new TextView(this);
tv.setText("just keep the text what you want here");
sv.addView(tv);
}
改变你的XML作为以下之一:
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ScrollView>
试试这个代码。它的作品....
+0
thanx的代码,但我做了同样的事情,但当文本增加屏幕大小滚动应该是他们向下滚动以查看其余文本,为什么它不是happen'n,pl指导我我是新的发展 – dashh 2012-07-21 12:51:06
答
在你的XML,写这篇文章的TextView:
<TextView
android:id="@+id/txtDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="7"
android:scrollbars="vertical"
android:text="TextView"
/>
而且在Activity
,这样写:
TextView txtDetails = (TextView) findViewById(R.id.txtDetails);
txtDetails.setText("Your Text");
txtDetails.setMovementMethod(new ScrollingMovementMethod());
这将滚动文本TextView
。无需写入ScrollView
。
请发布您的XML布局文件.. – Venkatesh 2012-07-21 05:15:58
http://www.helloandroid.com/tutorials/how-draw-multiline-text-canvas-easily我认为这个链接可以帮助你更好。 – Venkatesh 2012-07-21 05:30:22