我在创建项目时选择了Google地图活动,如何在布局中添加按钮? 对不起,如果这是一个愚蠢的问题,我是Android新手。
<Button
android:id="@+id/btn_draw_State"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="right|top"
android:layout_marginTop="55dp"
android:layout_marginRight="11dp" />
布局:
<fragment
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:id="@+id/map" tools:context=".MapsActivityWifi"
android:name="com.google.android.gms.maps.SupportMapFragment">
答案 0 :(得分:0)
FrameLayout旨在屏蔽屏幕上的某个区域以显示单个项目。使用LinearLayout或RelativeLayout
尝试此操作并根据需要更改按钮
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<fragment
android:layout_width="match_parent"
android:layout_height="instead of match parent try to give a value so that it does not occupy the whole screen"
android:id="@+id/map"
tools:context=".MapsActivityWifi"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
<Button
android:id="@+id/btn_draw_State"
android:layout_below="@id/map"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="right|top"
android:layout_marginTop="55dp"
android:layout_marginRight="11dp" />
答案 1 :(得分:0)
来自StackOverFlow PT
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapsActivityWifi"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
<Button
android:id="@+id/btn_draw_State"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="right|top"
android:layout_marginTop="55dp"
android:layout_marginRight="11dp" />
</FrameLayout>