我最近制作的应用程序有一些问题。它应该连接到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
它应该继续写“药房”和其他单词,就像其他行一样
发布于 2018-06-04 21:02:07
我找到了解决方案:
基本上,我在编辑我的帖子之前谈到的HTTPClient是我导入的一个类,它包含the following restriction。
我去掉了盖子,现在可以看到整个文本了。我仍然看不到应用程序上的换行,当我连接到我的树莓每个浏览器时,我清楚地看到,但我猜这是另一个问题,将导致另一个线程,谢谢!
发布于 2018-06-04 06:25:32
在你的TextView
中,像这样修改高度:
android:layout_height="wrap_content"
噢!如上所述,attr。应该删除maxLines
https://stackoverflow.com/questions/50671465
复制相似问题