当我试图添加一个按钮到我的布局,我不能编辑它或看到它,当我运行应用程序。我想Map碎片和按钮重叠了,但我不确定。有人知道解决办法吗?
提前谢谢。
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" />
2条答案
按热度按时间fwzugrvs1#
只需替换这两个:
我刚把textview的高度改为
wrap_content
在碎片上加上1的重量。2w2cym1i2#
与
LinearLayout
一个视图不可能与另一个视图重叠。LinearLayout
在你的例子中是垂直的,所以视图是一个接一个的。它的高度设置为match_parent
所以不能超过屏幕高度。让我们看下一步:
<fragment>
设置的高度match_parent
我也是。因此,这个父级采用了完整的布局高度,下面的视图缩小为零高度。你需要降低它的高度,使用wrap_content
或固定高度dp
.<TextView>
设置的高度match_parent
. 一切都和片段视图一样。降低它的高度。<Button>
就在这些视图的下方,只有在布局中有位置时才可见。