几个星期以来,我一直在这里询问我在使用此布局时遇到的问题,所以这次我将展示一张我需要的图片:
我想要一个 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/