Creating a chat layout?
I attempted to create a android chat layout in xml, but I could not get things how 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>
This results in this. The problem with this layout (which is pretty messy), is that I don't want the size of the lower LinearLayout to be a percentage. I want it to be a fixed height, and the TextView in the ScrollView(is this the best way to make large text scroll?) to fill up the rest of the screen. I must be missing some attribute or something.
Try not giving the bottom section a weight, but just wrap content, then have the top scroll fill remaining space by 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>
精彩评论