Creating a chat layout?

I tried to create an android chat layout in xml, but I could not get what I wanted. This is the closest I could get:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="10" > <TextView android:text="@string/text" android:id="@+id/textOutput" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="5dp" android:paddingRight="5dp" android:paddingTop="5dp" /> </ScrollView> <LinearLayout android:id="@+id/linearLayout1" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="100" android:paddingLeft="5dp" android:paddingRight="5dp" android:paddingBottom="5dp" android:baselineAligned="true"> <EditText android:layout_weight="1" android:id="@+id/textInput" android:layout_height="45dp" android:layout_width="fill_parent"> <requestFocus></requestFocus> </EditText> <Button android:layout_weight="1" android:text="Send" android:layout_height="45dp" android:layout_width="125dp" android:id="@+id/btnSend"></Button> </LinearLayout> </LinearLayout> 

As a result of this . The problem with this layout (which is pretty dirty) is that I do not want the size of the bottom LinearLayout to be a percentage. I want it to be a fixed height, and a TextView in a ScrollView (is this the best way to do a large scroll of text?) To fill the rest of the screen. I need to skip some attribute or something like that.

+6
source share
1 answer

Try not to give the bottom of the weight, but just wrap the contents, and then fill the top scroll space, leaving a free space, giving it a weight of 1. Like this

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ScrollView android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" > <TextView android:text="@string/text" android:id="@+id/textOutput" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="5dp" android:paddingRight="5dp" android:paddingTop="5dp" /> </ScrollView> <LinearLayout android:id="@+id/linearLayout1" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="5dp" android:paddingRight="5dp" android:paddingBottom="5dp" android:baselineAligned="true"> <EditText android:layout_weight="1" android:id="@+id/textInput" android:layout_height="45dp" android:layout_width="0dip"> <requestFocus></requestFocus> </EditText> <Button android:text="Send" android:layout_height="45dp" android:layout_width="125dp" android:id="@+id/btnSend"></Button> </LinearLayout> </LinearLayout> 
+8
source

Source: https://habr.com/ru/post/896754/


All Articles