文本结尾在TextView中消失

问题描述 投票:0回答:2

我最近制作的应用程序存在一些问题。它应该连接到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”和其他词,就像其他行一样

php android text textview
2个回答
0
投票

在你的TextView纠正高度,如下:

android:layout_height="wrap_content"

哦!并且如上所述attr。应该删除maxLines


0
投票

我找到了解决方案:

基本上,我在编辑帖子之前谈论的HTTPClient是我导入的一个类,它包括qazxsw poi。

我取下了帽子,现在可以看到整个文本了。我仍然看不到我在每个浏览器连接到我的覆盆子时清楚看到的应用程序上的换行符,但我想这是另一个导致另一个线程的问题,谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.