文本未显示在滚动视图中
Text not shwoing in the Scrollview
我正在开发一个必须实现聊天功能的应用程序。我在聊天 UI 时遇到问题。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/comment_rl"">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/comment_scrollView"
android:layout_alignParentTop="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/comment_ll">
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignBottom="@id/comment_scrollView"
android:background="#ffffff">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Back"
android:id="@+id/comment_back_btn"
android:layout_weight="1"
android:layout_gravity="bottom" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/comment_editText"
android:layout_weight="3" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Send"
android:id="@+id/comment_send_btn"
android:layout_weight="1"
android:layout_gravity="bottom" />
</LinearLayout>
</RelativeLayout>
在图像中,消息 "joool" 已正确发送,并且显示在屏幕上,正如我在我的数据库中看到的那样,但它实际上没有显示在 ui 中在后退按钮后面或屏幕外。所以我不确定如何解决这个问题?我坚持了 2 天,似乎无法找到一种方法将文本保持在编辑文本之上。
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String comment = (String) dataSnapshot.getValue();
Log.d("Tag", "comment" + comment);
LinearLayout.LayoutParams selected_qstn_comment_lp =
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
selected_qstn_comment_lp.setMargins(10,25,5,5);
selected_qstn_comment_lp.gravity = Gravity.CENTER;
TextView selected_qstn_comment =
new TextView(getApplicationContext());
selected_qstn_comment.setTextSize(14.0f);
selected_qstn_comment.setTextColor(Color.BLACK);
selected_qstn_comment.setPadding(10,5,0,0);
selected_qstn_comment.setText("\n" + comment + "\n");
selected_qstn_comment.setLayoutParams(selected_qstn_comment_lp);
ll.addView(selected_qstn_comment);
}
这是我填充应用聊天部分的地方。
注意:滚动视图实际上正在工作,因为我能够从上到下滚动。但它实际上并没有包含问题所在的全部内容。我想这是因为我给的利润?但我不确定,因为它实际上应该包装内容。
如下更改布局:
...
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/comment_scrollView"
android:layout_alignParentTop="true"
android:layout_above="@+id/my_linear">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/comment_ll">
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@id/my_linear"
android:background="#ffffff">
...
</LinearLayout>
我正在开发一个必须实现聊天功能的应用程序。我在聊天 UI 时遇到问题。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/comment_rl"">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/comment_scrollView"
android:layout_alignParentTop="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/comment_ll">
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignBottom="@id/comment_scrollView"
android:background="#ffffff">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Back"
android:id="@+id/comment_back_btn"
android:layout_weight="1"
android:layout_gravity="bottom" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/comment_editText"
android:layout_weight="3" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Send"
android:id="@+id/comment_send_btn"
android:layout_weight="1"
android:layout_gravity="bottom" />
</LinearLayout>
</RelativeLayout>
在图像中,消息 "joool" 已正确发送,并且显示在屏幕上,正如我在我的数据库中看到的那样,但它实际上没有显示在 ui 中在后退按钮后面或屏幕外。所以我不确定如何解决这个问题?我坚持了 2 天,似乎无法找到一种方法将文本保持在编辑文本之上。
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String comment = (String) dataSnapshot.getValue();
Log.d("Tag", "comment" + comment);
LinearLayout.LayoutParams selected_qstn_comment_lp =
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
selected_qstn_comment_lp.setMargins(10,25,5,5);
selected_qstn_comment_lp.gravity = Gravity.CENTER;
TextView selected_qstn_comment =
new TextView(getApplicationContext());
selected_qstn_comment.setTextSize(14.0f);
selected_qstn_comment.setTextColor(Color.BLACK);
selected_qstn_comment.setPadding(10,5,0,0);
selected_qstn_comment.setText("\n" + comment + "\n");
selected_qstn_comment.setLayoutParams(selected_qstn_comment_lp);
ll.addView(selected_qstn_comment);
}
这是我填充应用聊天部分的地方。
注意:滚动视图实际上正在工作,因为我能够从上到下滚动。但它实际上并没有包含问题所在的全部内容。我想这是因为我给的利润?但我不确定,因为它实际上应该包装内容。
如下更改布局:
...
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/comment_scrollView"
android:layout_alignParentTop="true"
android:layout_above="@+id/my_linear">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/comment_ll">
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@id/my_linear"
android:background="#ffffff">
...
</LinearLayout>