我想要显示2-3页长的文本,尝试使用滚动视图,但文本被切断,我是新手开发,请给出简单的例子,谢谢
发布于 2012-07-21 13:42:41
这将会起作用,诀窍是获得你想要在滚动视图中滚动的内容。
<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>发布于 2012-07-21 13:45:44
在可扩展标记语言中,编写以下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编写。
发布于 2012-07-21 13:29:44
文本被截断意味着你遇到了什么问题。尝试以下代码。它是有效的.
使用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>试试这段代码。它起作用了……
https://stackoverflow.com/questions/11589652
复制相似问题