创建一个聊天的布局?创建一个、布局

2023-09-07 08:38:39 作者:东京⊕樱花

我试图创建一个XML格式的安卓聊天的布局,但我无法得到的东西我怎么想。这是最接近我能得到:

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>

这导致这个。 用此布局的问题(这是pretty的杂乱),是我不希望的低的LinearLayout的大小是一个百分比。我想这是一个固定的高度,并在滚动型TextView的(这是为了让大文字滚动的最好方法?)来填充屏幕的其余部分。我必须失去一些属性或什么的。

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.

推荐答案

尽量不要给底部的权重,但只是包装的内容,然后有顶部滚动填补赋予其1这样的重量剩余空间

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>