简体   繁体   English

Android线性布局中的多行

[英]Multiple lines in a android linear layout

I'm fiddling around with writing android apps and what I'm currently trying to do is to have a text box with a send button at the top of the page and a black button bar at the bottom. 我摆弄着编写android应用程序的操作,我目前正在尝试做的是在页面顶部有一个带有发送按钮的文本框,在底部有一个黑色按钮栏。

I understand from this question that the correct way to do this would be to write something like this: 我从这个问题中了解到,执行此操作的正确方法是编写如下内容:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_height="wrap_content"
    <EditText android:id="@+id/edit_message"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:hint="@string/edit_message" 
        android:layout_gravity="top|center"/>

     <Button
        android:layout_width="wrap_content"
        android:text="@string/button_send" 
        android:onClick="sendMessage"/>
     </LinearLayout>

     <LinearLayout android:id="@+id/footer"
         android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        style="@android:style/ButtonBar">

    <Button android:id="@+id/saveButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/menu_done" />

    <Button android:id="@+id/cancelButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/menu_cancel" />
</LinearLayout>
</LinearLayout>

but the black bar and the text box just end up on top of each other :( 但是黑条和文本框仅在彼此之上:(

I'm not sure if these are cut-and-past errors, but I noticed a few things in the xml. 我不确定这些是否是剪切和过去的错误,但是我注意到xml中的一些内容。 The first nested linear layout is missing a '>' before the EditText and doesn't specify a layout_height. 第一个嵌套的线性布局在EditText之前缺少“>”,并且未指定layout_height。 And the first button also doesn't have a layout_height. 而且第一个按钮也没有layout_height。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM