【发布时间】:2020-05-17 12:43:11
【问题描述】:
试图将视图附加到片段的左下角并且它不服从我的命令:(
代码编译并运行,但按钮位于屏幕的左上角。
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity">
<ImageButton
android:id="@+id/searchBtn"
android:layout_width="150dp"
android:layout_height="150dp"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="centerInside"
map:layout_constraintBottom_toBottomOf="parent"
map:layout_constraintStart_toStartOf="parent"
map:srcCompat="@drawable/loupe"/>
</fragment>
android studio 的新手,还没有完全理解所有的模式,所以我觉得我可能试图以错误的方式做某事。
我应该定义某种容器,然后将地图片段和按钮放入其中吗?
但如果我这样做,它会破坏我的主地图代码。
【问题讨论】:
-
命令
layout_constraintBottom_toBottomOf和layout_constraintStart_toStartOf用于ConstraintLayout。如果要使用它们,则需要将视图放在 ConstraintLayout 中。但是,请查看此question,了解如何布置片段。片段布局不应该放在<fragment>标签内,它应该是它自己的文件。
标签: android android-layout android-fragments android-constraintlayout