android - Android Studio如何为片段内的视图设置约束
问题描述
试图将视图附加到片段的左下角并且它不服从我的命令:(
代码编译并运行,但按钮位于屏幕的左上角。
<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 的新手,还没有完全理解所有的模式,所以我觉得我可能试图以错误的方式做某事。
我应该定义某种容器,然后将地图片段和按钮放入其中吗?
但是,如果我这样做,它会在我的 main.js 中破坏地图代码。
解决方案
不确定您要问什么,但据我了解,您希望将 ImageButton 放置在片段顶部。您可以将其添加到您的按钮 android:layout_gravity="bottom|start"
以定位您的按钮。