文本结尾在 TextView 中消失

End of text dissapears in TextView

我最近制作的应用程序有一些问题。 它应该连接到 Raspberry 并执行一个 PHP 页面,该页面使用 preg_match_all 过滤 3 个文本文档并显示 3 行文本以及今天的日期和时间。

我遇到的问题是,当文本超过 5 行时(几乎总是如此),最后一行从 TextView 中消失并且不可见。

我尝试了很多来自其他论坛的东西,但似乎没有任何帮助(这也意味着我的代码可能有点混乱)

因此,这是 MainActivity 代码:

public class MainActivity extends AppCompatActivity {

private HttpClient mHttpClient;
TextView result;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    new connectTask().execute("");
    result = findViewById(R.id.result);
    Toast.makeText(getApplicationContext(), "connexion", Toast.LENGTH_LONG);
    if (VERSION.SDK_INT > 9) {
        StrictMode.setThreadPolicy(new Builder().permitAll().build());
    }

}

public class connectTask extends AsyncTask<String, String, HttpClient> {
    @Override

    protected HttpClient doInBackground(String... message) {
        mHttpClient = new HttpClient("http://192.168.0.51", new HttpClient.OnMessageReceived() {
            @Override
            public void messageReceived(String message) {
                publishProgress(message);
                Log.d("doInbackGround", "recu " + message);
            }
        });
        mHttpClient.run();
        return null;
    }
    @Override
    @RequiresApi(api = 24)
    protected void onProgressUpdate(String... values) {

        super.onProgressUpdate(values);


        String resu = result.getText().toString();
        resu = resu + values[0];

        result.setText(Html.fromHtml(resu, Html.FROM_HTML_MODE_LEGACY));
        result.setMovementMethod(new ScrollingMovementMethod());

    }

}
}

这是我的 MainActivity XML 布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLines="8"
    android:ellipsize="end"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/result"
        android:layout_width="fill_parent"
        android:layout_gravity="fill"
        android:layout_height="391dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:singleLine="false"
        android:freezesText="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

And this a picture preview of what it looks like

应该继续写 "PHARMACIE " 和其他单词,就像其他行一样

在您的 TextView 中更正高度:

android:layout_height="wrap_content"

哦!如上所述,attr。 maxLines 应删除

我找到了解决方案:

基本上,我在编辑 post 之前所说的 HTTPClient 是我导入的 class,它包括 the following restriction.

我去掉了上限,现在可以看到整个文本了。当我通过浏览器连接到我的树莓派时,我仍然看不到应用程序上的换行符,但我想这是另一个问题,会导致另一个线程,谢谢!