线性布局中的叠加浮动按钮

时间:2015-04-20 06:15:17

标签: java android xml android-linearlayout overlay

我有这样的布局:

enter image description here

但是正如您所看到的,浮动按钮不会覆盖编辑文本。有没有办法在LinearLayout中执行此操作? (我不能使用其他布局)。

我在SO上看过很多答案,但所有答案都使用RelativeLayoutFrameLayout

这是我的xml(浮动按钮在最后) -

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="New Button"
            android:id="@+id/button" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="New Button"
            android:id="@+id/button2" />

    </LinearLayout>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4"
        android:layout_gravity="center_horizontal"
        android:id="@+id/editText" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4"
        android:layout_gravity="center_horizontal"
        android:id="@+id/editText2" />

    <!--Overlay this image -->

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/ic_mic"
        android:layout_gravity="right" />

</LinearLayout>

以下是我希望它的样子 -

enter image description here

1 个答案:

答案 0 :(得分:0)

使用FrameLayout,如下面的代码:

<FrameLayout
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" >

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/ic_mic"/>
</FrameLayout>