2017-10-12 2 views
-1

フレームレイアウト内に2つの線形レイアウトがあるAndroidスタジオに次のコードがあります。ただし、両方のレイアウトのボタンは、互いの上にマップされます。 2つの線形レイアウト(ボタンを含む)を他の桃の上にマッピングするのではなく、縦に並べて配置することは可能ですか?フレームレイアウト内の線形レイアウト

<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

なぜFrameLayoutの代わりにLinearLayoutまたはRelativeLayoutを使用しようとしないのですか? – 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にラップできます。この場合、そのルートFrameLayoutLinearLayoutと置き換えてandroid:orientation="vertical"と置き換えて、2つを縦に並べることができます。

関連する問題