Creating a chat layout?

前端 未结 1 1747
庸人自扰
庸人自扰 2021-01-05 18:20

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:



        
相关标签:
1条回答
  • 2021-01-05 18:30

    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>
    
    0 讨论(0)
提交回复
热议问题