当我试图在布局中添加按钮时,我无法编辑它,也无法在运行应用程序时看到它。我认为地图碎片重叠了按钮,但我不确定。有人知道解决方案吗?
提前谢谢。
Roan Kers布局:布局xml:
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme">
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/toolbar"
android:layout_alignStart="@+id/toolbar" />
</androidx.appcompat.widget.Toolbar>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
只需替换这两个:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
我只是将TextView的高度更改为wrap_content
,并将layout_weight of 1添加到片段中。
使用LinearLayout
时,一个视图不可能与另一个视图重叠。
LinearLayout
在您的情况下是垂直的,所以视图是一个在另一个下面的。其高度设置为match_parent
,因此不能大于屏幕高度。
让我们看看下一个:
- 也为
match_parent
设置了<fragment>
高度。因此,这个父级占用了整个布局高度,下面的视图缩小为零高度。您需要降低其高度,使用wrap_content
或dp
中的固定高度 - 为
match_parent
设置的<TextView>
高度。一切都与片段视图相同。减小其高度 <Button>
就在这些视图下方,只有在布局中有位置时才可见