Android 如何在地图下方显示两个水平按钮

Android 如何在地图下方显示两个水平按钮,android,android-layout,button,Android,Android Layout,Button,目前在我的代码中,按钮一个接一个地显示,地图显示在它们下面。我希望这两个按钮显示在同一条线上和地图下方 我的代码是: <?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layo

目前在我的代码中,按钮一个接一个地显示,地图显示在它们下面。我希望这两个按钮显示在同一条线上和地图下方

我的代码是:

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

     <Button
         android:id="@+id/btnProgram"
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         android:text="Program" />

     <Button
         android:id="@+id/btnAfisareStatii"
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         android:text="Afisare Statii" />        

     <com.google.android.maps.MapView 
            android:id="@+id/mapView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:enabled="true"
            android:clickable="true"
            android:apiKey="0ws8opHdf-pIbZUa916nju81kSSlPRK4Wbg_0vg"
     />

    <WebView 
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />

    <WebView 
        android:id="@+id/webview2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</LinearLayout>

将两个按钮包装成水平直线布局,或使用相对线布局,如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btnProgram"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Program" />

    <Button
        android:id="@+id/btnAfisareStatii"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Afisare Statii" android:layout_toRightOf="@+id/btnProgram"/>

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/btnAfisareStatii" />

    <WebView
        android:id="@+id/webview2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/webview" />

    <com.google.android.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="0ws8opHdf-pIbZUa916nju81kSSlPRK4Wbg_0vg"
        android:clickable="true"
        android:enabled="true" android:layout_above="@id/btnProgram">
    </com.google.android.maps.MapView>

</RelativeLayout>

如果不需要,还应排列或删除webView的

尝试此布局:

<?xml version="1.0" encoding="UTF-8"?>  <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent">
<LinearLayout
     android:orientation="horizontal"
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent">

     <Button
         android:id="@+id/btnProgram"
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         android:text="Program" />

     <Button
         android:id="@+id/btnAfisareStatii"
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         android:text="Afisare Statii" />        

</LinearLayout>
 <com.google.android.maps.MapView 
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="0ws8opHdf-pIbZUa916nju81kSSlPRK4Wbg_0vg"
 />

<WebView 
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

<WebView 
    android:id="@+id/webview2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>


设置按钮所在的布局:方向:“水平” 使用以下命令:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="horizontal"
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent">


 <Button
     android:id="@+id/btnProgram"
     android:layout_height="wrap_content"
     android:layout_width="wrap_content"
     android:text="Program" />

 <Button
     android:id="@+id/btnAfisareStatii"
     android:layout_height="wrap_content"
     android:layout_width="wrap_content"
     android:text="Afisare Statii" />        


我按照你对我说的做了,但是现在按钮显示在同一行上,地图不显示。你能告诉我如何制作按钮来填充每行的一半吗?嗯。。为此,您确实需要使用android:weightSum=“1”,将两个按钮包装成一个水平的
线性布局
,并为每个按钮设置
android:layout\u weight=“0.5”
。我这样做了,但现在只显示地图,按钮看起来不够逼真,如果没有在相对的内部设置好Linearlayout属性;我建议您首先尝试了解线性和相对布局是如何工作的;在这里阅读更多:谢谢,我将查看链接