1
프로그래밍 방식으로 하단의 수직 선형 뷰에 뷰를 추가해야합니다. (예, 알겠습니다. 제목에 있습니다.)하단의 수직 LinearLayout에 뷰 추가 (프로그래밍 방식으로)
Ok : 선형보기에보기를 추가 할 수 있습니다. 문제가되지 않습니다. 하지만 그것은 채팅을위한 것이므로 표시되는 각 메시지의 하단에보기를 추가해야합니다. LinearLayout에 어떤 속성도 없다.
추가 메시지 :
mHandler.post(new Runnable() {
@Override
public void run() {
TextView message = new TextView(ChatActivity.this);
String[] splitMessage = text.split(":");
message.setText(splitMessage[0]+"\n"+splitMessage[1]);
message.setGravity(Gravity.LEFT);
message.setMaxWidth(200);
message.setBackgroundColor(getResources().getColor(android.R.color.tertiary_text_light));
message.setTextColor(getResources().getColor(android.R.color.black));
message.setSingleLine(false);
mLayout.addView(message);
}
});
chat_layout.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/live_obs_mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/empty"
android:orientation="vertical" >
<ScrollView
android:id="@+id/chat_layout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="10" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:isScrollContainer="tue"
>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_chat"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_gravity="left|center_vertical"
android:layout_weight="5" />
<Button
android:id="@+id/chat_submit"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_gravity="right|center_vertical"
android:onClick="onSubmit"
android:text="OK" />
</LinearLayout>
</LinearLayout>
실제로 선형 레이아웃의 하단에보기가 추가되었으므로 사실 내 질문은 어리 석습니다. 단지 LinearLayout에 RelativeLayout을 배치하고 새 메시지가 나타날 때 크기를 조정하면됩니다. 나는 피곤했다 ... 하지만 이것을 이해하는 데 도움이되기 때문에 귀하의 게시물에 대한 thx : – QLag
괜찮습니다. 천만에요. – VendettaDroid