首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在android中编写要在屏幕上显示的长文本,以便屏幕向下移动

在android中编写要在屏幕上显示的长文本,以便屏幕向下移动
EN

Stack Overflow用户
提问于 2012-07-21 13:08:56
回答 3查看 23.7K关注 0票数 3

我想要显示2-3页长的文本,尝试使用滚动视图,但文本被切断,我是新手开发,请给出简单的例子,谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-07-21 13:42:41

这将会起作用,诀窍是获得你想要在滚动视图中滚动的内容。

代码语言:javascript
复制
<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>
票数 4
EN

Stack Overflow用户

发布于 2012-07-21 13:45:44

在可扩展标记语言中,编写以下TextView:

代码语言:javascript
复制
<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中,编写以下代码:

代码语言:javascript
复制
TextView txtDetails = (TextView) findViewById(R.id.txtDetails);
txtDetails.setText("Your Text");
txtDetails.setMovementMethod(new ScrollingMovementMethod());

这将滚动TextView中的文本。不需要用ScrollView编写。

票数 11
EN

Stack Overflow用户

发布于 2012-07-21 13:29:44

文本被截断意味着你遇到了什么问题。尝试以下代码。它是有效的.

使用xml代码:

代码语言:javascript
复制
  <?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:

代码语言:javascript
复制
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

代码语言:javascript
复制
  <?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>

试试这段代码。它起作用了……

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11589652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档