Android:向 Fragment 添加一个很长的 TextView

我正在尝试在片段中添加一个很长的文本(Glgamesh 的史诗)。


我的 xml 版本:


<LinearLayout.LayoutParams xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:orientation="vertical"

    tools:context=".viewOne">


    <TextView

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:id="@+id/epica"

        android:text=" **I WILL INSERT HERE THE WHOLE TEXT?**" />


</LinearLayout.LayoutParams>

还有什么是java部分?我必须重写 setText 中的内容吗?凭身份证能回忆起来吗?


    @Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.dynamic_linearlayout);


    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.epica);


TextView textView = new TextView(this);

    textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,

            LayoutParams.WRAP_CONTENT));

嘿,谢谢!


catspeake
浏览 218回答 1
1回答

森栏

如果你试图让 APP 像一本有页面的书,你不能这样做。您必须创建一个数据库来存储每个页面的内容。然后,当用户点击按钮时,您可以将一页一页地加载到文本视图中。您提供的 java 代码可以更改如下。&nbsp; &nbsp; @Override&nbsp; &nbsp; protected void onCreate(Bundle savedInstanceState) {&nbsp; &nbsp; &nbsp;super.onCreate(savedInstanceState);&nbsp; &nbsp; &nbsp;setContentView(R.layout.dynamic_linearlayout);&nbsp; &nbsp; &nbsp;TextView epica = (Textview) findViewById(R.id.epica);&nbsp; &nbsp; &nbsp;epica.setText("Some text here");
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java