Делаю маленький чат, и нужно по клике на кнопочку "send" добавлять новый вид с текстом сообщения.
Пока-что для теста пробую добавить обычный LinearLayout с двумя кнопками.
Вот что я пробую сделать.
chat.xml
Код: Выделить всё
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/chatBackground">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:weightSum="1.0"
android:id="@+id/scrollChatMessagesOutput">
<TextView
android:id="@+id/chatMessagesOutput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:text="@string/chat_Text" />
</ScrollView>
<LinearLayout
android:id="@+id/chatBottomLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<EditText
android:id="@+id/chatTextInput"
android:layout_width="0dip"
android:layout_height="45dp"
android:layout_weight="1" >
<requestFocus>
</requestFocus>
</EditText>
<Button
android:id="@+id/btnSend"
android:layout_width="125dp"
android:layout_height="45dp"
android:text="@string/btnSend"
android:onClick="onChatSendBtnClick">
</Button>
</LinearLayout>
</LinearLayout>
Код: Выделить всё
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1.0"
android:id="@+id/chatMessage">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".70"
android:text="left" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".30"
android:text="right" />
</LinearLayout>
Код: Выделить всё
private void addMessageToStage(Message message){
LinearLayout scrollChatMessagesOutput = (LinearLayout)findViewById(R.id.chatBottomLayout);
LinearLayout insertPoint = (LinearLayout)findViewById(R.id.chatMessage);
scrollChatMessagesOutput.addView(insertPoint);
}