【发布时间】:2015-04-20 06:15:17
【问题描述】:
我有这样的布局:
但如您所见,浮动按钮并未覆盖编辑文本。 LinearLayout 有没有办法做到这一点? (我不能使用其他布局)。
我在 SO 上看到了很多答案,但他们都使用 RelativeLayout 或 FrameLayout。
这是我的 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>
这是我想要的样子 -
【问题讨论】:
-
所有其他答案都使用 FrameLayout 或 RelativeLayout 是有原因的。 LinearLayout 就像命名的那样,Linear。它不支持图层。请在您阅读的其他答案中使用 FrameLayout 或 RelativeLayout。
-
使用框架布局来实现这一点
-
你不能只使用线性布局来实现你想要的,你必须使用框架布局
-
好的。感谢您的建议。
标签: java android xml android-linearlayout overlay