安卓布局: one widget scrollable and two fixed at bottom

标签 android xml android-layout textview scrollable

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

enter image description here

我想要一个 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>

最佳答案

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

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 的原因。)

关于安卓布局: one widget scrollable and two fixed at bottom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8260782/

相关文章:

android - Qt 安卓 : How to show the native file dialog?

c# - 找不到 xml 路径错误

c# - 尽管以 UTF-8 编写 XML,但在 XmlElement 中转义 Unicode 字符串

javascript - 缩略图库的 XML 数据图像绑定(bind)

android - 无用的父布局

Android 样式 : Difference between 'style="@android:style/XYZ "' and ' style ="?android:attr/XYZ"'?

Android包括布局文件(引用id)

android发送短信并获得越来越多的发送和传递通知

java - 如何判断 editText 是否处于焦点?

android - 在 Android 中以编程方式强制停止应用程序