0

当我尝试将按钮添加到我的布局时,我无法编辑它或在运行应用程序时看到它。我认为地图片段与按钮重叠,但我不确定。有人知道解决方案吗?

提前致谢。

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" />
4

2 回答 2

0

只需替换这两个:

<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 的 1 添加到片段中。

于 2020-12-01T12:33:59.760 回答
0

LinearLayout一个视图不可能与另一个视图重叠。

LinearLayout在您的情况下是垂直的,因此视图在另一个下方。它的高度设置为match_parent不能大于屏幕高度。

我们接下来看看:

  • <fragment>高度也设置match_parent了。所以这个父级采用完整的布局高度,而低于的视图缩小到零高度。您需要降低其高度,使用wrap_content或固定高度dp
  • <TextView>高度设置为match_parent。一切都与片段视图相同。降低它的高度。
  • <Button>就在这些视图的下方,只有在布局中有位置时才可见。
于 2020-12-01T12:46:59.013 回答