1

几周以来我一直在这里询问或我在使用此布局时遇到的问题,所以这次我将展示我需要的图片:

在此处输入图像描述

我希望始终在屏幕底部有一个 EditText 和一个 Button (当键盘出现时,它们必须出现在键盘上方,而不是留在键盘下方)。空闲屏幕的其余部分必须是可滚动的 TextView。

编辑:这是现在的代码,遵循 Romain 的指示。一切都按预期工作,但滚动。TextView 必须是可滚动的,但不是。如何解决?

<?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">

    <TextView
        android:id="@+id/consola"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:scrollbars = "vertical"
        android:height="0dip"
        android:layout_weight="1.0"/>

    <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="bottom">

        <EditText 
        android:id="@+id/editText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

        <Button
            android:text="Conectar"
            android:id="@+id/boton"
            android:label="@string/enviar_string"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
        </Button>
    </LinearLayout>
</LinearLayout>
4

3 回答 3

5

你的布局太复杂了,这里是你应该做的一个精简版:

LinearLayout width=fill_parent height=fill_parent orientation=vertical
    TextView width=fill_parent height=0dip layout_weight=1.0
    EditText width=fill_parent height=wrap_content
    Button width=fill_parent height=wrap_content

TextView 上的 layout_weight 是关键:它告诉父 LinearLayout 你想给这个 TextView 所有剩余的空白空间(这也是高度设置为 0dip 的原因。)

于 2011-11-24T17:49:49.803 回答
1

我终于自己找到了解决方案:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView   
android:id="@+id/scroller"  
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:height="0dip"
android:layout_weight="1.0">  

    <TextView
        android:id="@+id/consola"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"/>

</ScrollView>

<EditText 
    android:id="@+id/editText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom">

    <Button
        android:text="Conectar"
        android:id="@+id/boton"
        android:label="@string/enviar_string"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </Button>
</LinearLayout>

于 2011-11-28T16:00:19.277 回答
0

isScrollContainer如果需要显示软键盘,则在 TextView 上设置为 true 允许它调整大小。将 android:windowSoftInputMode=" adjustResize " 添加到清单中的活动中。

一些稍微过时的文档

于 2011-11-24T22:38:43.080 回答