[英]Add JTabbedPane with buttons, labels … in a frame with an absolute layout
[英]Add multiple buttons to Frame Layout (android)
我有一個在框架布局中使用 Google 地圖的應用程序。 我在這個(接受的)答案中使用了替代方案 2。 當我使用備選方案 2 時,我在應用程序頂部有一個按鈕(自由抽獎)。 我的問題是,我可以在此按鈕的兩側添加多個按鈕(水平/垂直)嗎?
我在網上搜索過類似的問題,但大多數情況下,答案涉及兩個單獨的布局。 我是 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>
關於您的錯誤“多個根標簽”: Android Studio 中的多個根標簽
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.