Android-按钮上方的文本

Android-按钮上方的文本,android,Android,我想在一行按钮上方放置一个可滚动的EditText,这样文本组件就可以填充按钮留下的所有垂直空间。事实证明,这非常困难,尤其是因为ADT有缺陷:它表明这种布局可以,而且在Eclipse中也可以,但在实际应用程序中却不行 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_hei

我想在一行按钮上方放置一个可滚动的EditText,这样文本组件就可以填充按钮留下的所有垂直空间。事实证明,这非常困难,尤其是因为ADT有缺陷:它表明这种布局可以,而且在Eclipse中也可以,但在实际应用程序中却不行

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <EditText android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/view1"/>
    <LinearLayout android:id="@id/view1"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true">
        <!-- buttons go here -->
    </LinearLayout>
</RelativeLayout>

在这个布局中,文本会延伸到全屏,正如您所期望的那样,也就是说,它位于按钮下方,但ADT图形布局工具显示它在按钮上方停止。如果你给它一个包裹的高度,那么它当然不会拉伸。布局和重量也没有帮助

那么,有办法吗?您必须在模拟器或真实设备上测试答案,而不仅仅是在Eclipse中


精确性:让我觉得这不起作用的是底部滚动条的形状(见下图):它应该在两端都是圆形的,相反,它看起来底部延伸得更远。如果你将它底部的形状与顶部的形状进行比较(不幸的是,我无法捕捉到:它消失得太快了),它显然是不同的。OTOH文本窗口小部件边界看起来与预期的一样。这很令人困惑。也许只是安卓系统中的一个小错误

请尝试以下代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:inputType="textMultiLine" >

        <requestFocus></requestFocus>
    </EditText>
    <LinearLayout
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent">
        <Button
            android:text="Button"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:id="@+id/button1"
            android:layout_width="0dp"></Button>
        <Button
            android:text="Button"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:id="@+id/button2"
            android:layout_width="0dp"></Button>
        <Button
            android:text="Button"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:id="@+id/button3"
            android:layout_width="0dp"></Button>
    </LinearLayout>
</LinearLayout>

这应该行得通

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">   
    <LinearLayout android:id="@+id/view1" android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true">
        <Button android:text="Button" android:layout_weight="1"
            android:layout_height="wrap_content" android:id="@+id/button1"
            android:layout_width="0dp"/>
        <Button android:text="Button" android:layout_weight="1"
            android:layout_height="wrap_content" android:id="@+id/button2"
            android:layout_width="0dp"/>
        <Button android:text="Button" android:layout_weight="1"
            android:layout_height="wrap_content" android:id="@+id/button3"
            android:layout_width="0dp"/>
    </LinearLayout>
    <EditText android:id="@+id/text1" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_above="@id/view1"
        android:gravity="top"/>
</RelativeLayout>

我对TextView和底部的一个按钮做了同样的事情。我尝试将EditText放在TextView的位置,它对我来说很好。你可以试试这个-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF">   

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:text="Add New Template"
        android:layout_gravity="bottom"     
        android:layout_alignParentBottom="true"/>

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/editText"
        android:layout_alignParentTop="true"
        android:layout_above="@id/add_acronym"
    />
</RelativeLayout>

这是快照-


android:layout\u over=“@+d/view1”/>
它不应该是
android:layout\u over=“@+id/view1”/>
为什么不试试线性布局而不是相对布局呢?我想,那会解决你的问题。@PH7,是的,那是个打字错误;我刚刚修复了它。@Hiral否,使用linear,您将失去指定文本小部件必须在按钮处停止并匹配的选项。\u parent导致它真正占据整个屏幕。@Olefever。如果这是适合您的答案,请接受答案。不幸的是,这不是答案,因为文本小部件没有垂直拉伸!我想他希望编辑文本只和按钮一样宽?如果是,则顶部LinearLayout的布局宽度应为环绕_content@FunkTheMonk我不认为我最初的描述令人困惑。这显然是关于垂直拉伸,而不是水平拉伸。@olefevre,我只是做了一些改变。请看!因为fill_parent与match_parent是相同的布局,我已经尝试过了。下面我对blessenm的评论适用。