Android 嵌套线性布局工作不正常

Android 嵌套线性布局工作不正常,android,Android,我希望编辑文本和发送按钮在一行中,但图像在另一行中…但是使用此代码编辑文本、发送按钮和图像在一行中显示..您能告诉我如何在另一行中显示图像吗 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

我希望编辑文本和发送按钮在一行中,但图像在另一行中…但是使用此代码编辑文本、发送按钮和图像在一行中显示..您能告诉我如何在另一行中显示图像吗

<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"
        android:orientation="horizontal"
        tools:context=".MainActivity" >
    <EditText
        android:id="@+id/edit_message "
        android:layout_weight="1" 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message"/>

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

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

    <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/logo" />

    </LinearLayout>


    </LinearLayout>


若要使ImageView显示在EditText和按钮下方的一行中,您需要将外部线性布局的方向设置为垂直,然后将EditText和按钮以水平方向缠绕在线性布局中。

若要使ImageView显示在EditText和按钮下方的一行中,您需要将外部线性布局的方向设置为垂直,然后以水平方向将编辑文本和按钮包装在线性布局中。

您可以将
编辑文本和
按钮包装在
线性布局中。

<LinearLayout
    android:orientation="vertical"
    ...>
    <LinearLayout
        ...>
        <EditText
           .../>
       <Button
          .../>
   </LinearLayout>
   <ImageView
     .../>
</LinearLayout>
<RelativeLayout
    ...>
   <EditText
       android:id="@+id/et"
       .../>
   <Button
     android:layout_toRightOf="@id/et"
     .../>
   <ImageView
      android:layout_below="@id/et"
      .../>
</RelativeLayout>

但这也取决于你想要东西的确切位置。

你可以将你的
编辑文本和
按钮包装成
线性布局

<LinearLayout
    android:orientation="vertical"
    ...>
    <LinearLayout
        ...>
        <EditText
           .../>
       <Button
          .../>
   </LinearLayout>
   <ImageView
     .../>
</LinearLayout>
<RelativeLayout
    ...>
   <EditText
       android:id="@+id/et"
       .../>
   <Button
     android:layout_toRightOf="@id/et"
     .../>
   <ImageView
      android:layout_below="@id/et"
      .../>
</RelativeLayout>
<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"
    android:orientation="vertical"
    tools:context=".MainActivity" >

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

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

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

</LinearLayout>

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/logo" />

</LinearLayout>
但这也取决于你想要东西的确切位置。


<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"
    android:orientation="vertical"
    tools:context=".MainActivity" >

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

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

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

</LinearLayout>

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/logo" />

</LinearLayout>



嵌套线性布局工作不正常
我对此表示怀疑。@njzk2如果您阅读描述,您会发现他想说的是它没有按预期工作。是的。我想借此机会指出,这个标题不是很清楚。
嵌套线性布局工作不正常
我对此表示怀疑。@njzk2如果你阅读描述,你会发现他想说的是它没有按他预期的那样工作。是的。我想借此机会指出,这个标题不是很清楚。如果你看一下他上面的编辑文本,他打算在该元素上使用权重,如果他将所有元素都包装在一个RelativeLayout@ChrisM当然,但是如果没有图像,我不会猜测OP到底想要什么。这就是我给他选择的原因。是的,如果确实需要
weight
,那么OP可以使用第一个选项I gavei如果您查看上面的EditText,他打算在该元素上使用权重,如果他将它们全部包装在一个RelativeLayout@ChrisM当然,但是如果没有图像,我不会猜测OP到底想要什么。这就是我给他选择的原因。对如果确实需要
weight
,那么OP可以使用第一个选项I gavei如果这是您要查找的答案,请使用左侧的复选标记将其标记为答案:)是的,它可以工作,但我的发送按钮没有显示在右上角。请在右侧留出一些空间..但因为我想通过edittext和send使用完整的空间按钮在上面的代码中出现这种情况的原因是,您需要将水平线性布局的布局宽度设置为“匹配父级”,Chris M说的是对的,如果您将第二个线性布局设置为widht=math\U父级,您的按钮将显示,它不显示的原因是因为wrapcontent会询问其子级需要显示什么。很可能,edittext要求的空间太大,因此按钮在右侧屏幕外绘制。顺便说一句,如果这个答案是你想要的,请将它标记为已回答,每次我们发布正确的答案,我们都会赢得声誉,谢谢!另外,您在编辑文本中使用了权重,如果您希望在两个组件之间划分空间,我建议您也在按钮上使用权重,如果这是您要查找的答案,请使用左侧的复选标记将其标记为答案:)是的,它可以工作,但我的发送按钮没有显示在右上角。请在右侧留出一些空间..但由于我想通过edittext和发送按钮使用全部空间,原因是上面的代码是因为您需要将水平线性布局的布局宽度设置为“匹配父对象”Chris M说的是对的,如果您将第二个线性布局设置为widht=math\u父对象,则按钮将显示,它不显示的原因是因为wrapcontent询问其子对象最可能需要显示自己的内容,编辑文本要求的空间太大,因此按钮在右侧屏幕外绘制。顺便说一句,如果这个答案是你想要的,请将它标记为已回答,每次我们发布正确的答案,我们都会赢得声誉,谢谢!另外,您在编辑文本中使用了权重,如果您希望在两个组件之间划分空间,我建议您也在按钮上使用权重,否则它们将不会像预期的那样显示^^^是的,它可以工作,但我的发送按钮没有显示在右上角。左上角有一些空间到右侧..但由于我想通过edittext和发送按钮使用完整空间,所以它可以工作,但我的发送按钮没有显示在右上角。左上角有一些空间到右侧..但我想使用完整空间按编辑文本和发送按钮分隔空间