Php 文本视图中的文本结尾消失
我最近制作的应用程序有一些问题。 它应该连接到一个树莓并执行一个PHP页面,该页面使用preg_match_all过滤3个文本文档并显示3行文本以及今天的日期和时间 我遇到的问题是,当文本长度超过5行(几乎总是这样)时,最后一行就会从TextView中消失,并且不可见 我从其他论坛尝试了很多东西,但似乎没有任何帮助(这也意味着我的代码可能有点混乱) 下面是主要活动的代码:Php 文本视图中的文本结尾消失,php,android,text,textview,Php,Android,Text,Textview,我最近制作的应用程序有一些问题。 它应该连接到一个树莓并执行一个PHP页面,该页面使用preg_match_all过滤3个文本文档并显示3行文本以及今天的日期和时间 我遇到的问题是,当文本长度超过5行(几乎总是这样)时,最后一行就会从TextView中消失,并且不可见 我从其他论坛尝试了很多东西,但似乎没有任何帮助(这也意味着我的代码可能有点混乱) 下面是主要活动的代码: public class MainActivity extends AppCompatActivity { private
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());
}
}
}
public类MainActivity扩展了AppCompatActivity{
私有HttpClient mHttpClient;
文本视图结果;
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
新建connectTask()。执行(“”);
结果=findViewById(R.id.result);
Toast.makeText(getApplicationContext(),“connexion”,Toast.LENGTH\u LONG);
如果(VERSION.SDK_INT>9){
StrictMode.setThreadPolicy(新建生成器().permitAll().build());
}
}
公共类connectTask扩展了AsyncTask{
@凌驾
受保护的HttpClient doInBackground(字符串…消息){
mHttpClient=新的HttpClient(“http://192.168.0.51,新的HttpClient.OnMessageReceived(){
@凌驾
已接收公共无效消息(字符串消息){
出版进度(信息);
Log.d(“doInbackGround”、“recu”+消息);
}
});
mHttpClient.run();
返回null;
}
@凌驾
@要求api(api=24)
受保护的void onProgressUpdate(字符串…值){
super.onProgressUpdate(值);
字符串resu=result.getText().toString();
resu=resu+值[0];
result.setText(Html.fromHtml(resu,Html.FROM_Html_MODE_LEGACY));
result.setMovementMethod(新的ScrollingMovementMethod());
}
}
}
这是我的主要活动的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>
它应该继续写“PHARMACIE”和其他单词,就像文本视图中的其他行一样,更正高度如下:
android:layout_height="wrap_content"
哦!!如上所述,attrmaxLines
应该被删除我找到了解决方案:
基本上,我在编辑我的文章之前谈论的HTTPClient是我导入的一个类,它包括了
我去掉了封盖,现在可以看到全文了。我仍然看不到应用程序上的换行符,当我连接到我的raspberry per浏览器时,我清楚地看到了这些换行符,但我想这是另一个问题,将导致另一个线程,谢谢 您在TextView上尝试过android:layout\u height=“wrap\u content”吗?我是否可以假设您在HttpClient
中检索数据时没有任何问题?如果确实是这样,你可以从你的帖子中删除这部分代码。我将尝试你的建议,并作为正式问题回答提问者。是的,该部分正在工作,因此我将其从问题中删除,谢谢!我删除了我的答案,因为我误解了你想要的结果。我以为您希望在文本视图中最多显示5行。但您真正想要的是显示从文档中提取的行,并在TextView
中完整显示这些行?一点也不,您第一次做对了,我打开了3个txt文档,并使用preg_match_all从每个文档中获取1行。我还显示了日期和时间,所以大约有5行。在用“android:layout\u height=“wrap\u content”和“android:maxLines=“5”尝试了这个建议之后,我删除了关于maxLines的建议,但是我还是得到了同样的结果我相信问题出在ConstraintLayout
本身,因为它仍处于早期开发阶段,请尝试相对/线性布局,不要忘了删除ConstantLayout属性,也要去掉attr<代码>冻结文本