我有一個應用程序在框架佈局中使用Google地圖。我在this(接受)答案中使用替代方案2。當我使用替代方案2時,我在應用程序頂部有一個按鈕(自由繪製)。我的問題是,我可以在此按鈕的兩側添加多個按鈕(水平/垂直)嗎?將多個按鈕添加到框架佈局(android)
我在網上搜索了類似的問題,但主要是,答案涉及兩個單獨的佈局。我是Android的初學者,不知道如何使用兩個獨立的佈局。我嘗試使用兩種佈局,但出現錯誤「多根標籤」。有什麼辦法可以解決這個問題嗎?
任何幫助將不勝感激。
我有一個應用程序在框架佈局中使用Google地圖。我在this(接受)答案中使用替代方案2。當我使用替代方案2時,我在應用程序頂部有一個按鈕(自由繪製)。我的問題是,我可以在此按鈕的兩側添加多個按鈕(水平/垂直)嗎?將多個按鈕添加到框架佈局(android)
我在網上搜索了類似的問題,但主要是,答案涉及兩個單獨的佈局。我是Android的初學者,不知道如何使用兩個獨立的佈局。我嘗試使用兩種佈局,但出現錯誤「多根標籤」。有什麼辦法可以解決這個問題嗎?
任何幫助將不勝感激。
像這樣的事情在你的root_map.xml會給你相鄰的兩個按鈕,在地圖的左上角:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
<LinearLayout
android:id="@+id/fram_map"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btn_draw_State"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Free Draw" />
<Button
android:id="@+id/btn_dosomethingelse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do Something Else" />
</LinearLayout>
</FrameLayout>
是的,當然。你可以添加儘可能多的按鈕,只要你喜歡。要控制它們在FrameLayout中的位置,您必須使用android:layout_gravity
屬性爲每個孩子分配重力。
例子:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<Button
android:id="@+id/buttonA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button A"/>
<Button
android:id="@+id/buttonB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button B"/>
</LinearLayout>
</FrameLayout>
關於您的錯誤 「多根標籤」:Multiple root tags in Android Studio