2017-10-12 207 views
-1

我在Android Studio中有以下代碼,其中我在框架佈局中有兩個線性佈局。但是,兩個佈局中的按鈕都映射到彼此的頂部。是否可以將兩個線性佈局(包括按鈕)垂直放置,而不是映射到另一個桃子的頂部?框架佈局內的線性佈局

<FrameLayout 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:orientation="vertical" 
android:background="#FFFFFF" 
tools:context="com.dji.GSDemo.GoogleMap.MainActivity"> 


<fragment 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.SupportMapFragment" /> 

<FrameLayout 
    android:id="@+id/fram_map" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <Button 
      android:id="@+id/locate" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Locate" 
      android:layout_weight="1"/> 
     <Button 
      android:id="@+id/add" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Add" 
      android:layout_weight="1"/> 
     <Button 
      android:id="@+id/clear" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Clear" 
      android:layout_weight="1"/> 

     <Button 
      android:id="@+id/btn_draw_State" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Free Draw" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <Button 
      android:id="@+id/config" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Config" 
      android:layout_weight="0.9"/> 
     <Button 
      android:id="@+id/upload" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Upload" 
      android:layout_weight="0.9"/> 
     <Button 
      android:id="@+id/start" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Start" 
      android:layout_weight="1"/> 
     <Button 
      android:id="@+id/stop" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Stop" 
      android:layout_weight="1"/> 
    </LinearLayout> 

</FrameLayout> 

下面是按鈕的顯示的屏幕截圖。 Snap

+0

你可以添加它如何出現的截圖?你嘗試過相對佈局嗎? –

+0

爲什麼不嘗試使用LinearLayout或RelativeLayout而不是FrameLayout? – nhoxbypass

回答

1

嘗試在xml代碼的根目錄中將FrameLayout更改爲LinearLayout

並設置android:orientation="vertical"

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/fram_map" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <Button 
     android:id="@+id/locate" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Locate" /> 

    <Button 
     android:id="@+id/add" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Add" /> 

    <Button 
     android:id="@+id/clear" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Clear" /> 

    <Button 
     android:id="@+id/btn_draw_State" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Free Draw" /> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <Button 
     android:id="@+id/config" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.9" 
     android:text="Config" /> 

    <Button 
     android:id="@+id/upload" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.9" 
     android:text="Upload" /> 

    <Button 
     android:id="@+id/start" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Start" /> 

    <Button 
     android:id="@+id/stop" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Stop" /> 
</LinearLayout> 

</LinearLayout> 
1

FrameLayout將在屏幕上佈局所有孩子在同一幀。

如果您希望多個孩子垂直或水平堆疊,您可以將它們換成LinearLayout。在這種情況下,您可以簡單地將FrameLayout替換爲LinearLayoutandroid:orientation="vertical"以垂直堆疊兩個LinearLayout