简体   繁体   English

底部的Android MapView +按钮

[英]Android MapView + Buttons at the bottom

地图界面

I am trying to get a result similar to above but I am having difficulties getting the layout to reflect it. 我试图获得与上述类似的结果,但是我很难使布局反映出来。 So far I have managed to get the buttons to sit at the top fine but as soon as I want to move them to the bottom I can either only get them to be overlay or just completely disappear. 到目前为止,我已经设法使按钮位于顶部,但是一旦我想将它们移到底部,我就只能使它们被覆盖或完全消失。

I'm sure it's a pretty simple layout but I can't for the life of me get it. 我敢肯定这是一个非常简单的布局,但是我一生都无法理解。

The main view is a MapView, I want the mapview to give the buttons some space and basically just have the app background at the back of it. 主视图是一个MapView,我希望mapview为按钮提供一些空间,并且基本上只是在它的后面有应用程序背景。

Try to place a relative layout as parent to map view . 尝试将相对布局作为父视图放置在地图视图中。 Please find the XML snippet below: 请在下面找到XML代码段:

<!--  Use mapView is relative Layout if you want to do that.. i.e the view should overlay map. --!>

    <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
 <LinearLayout
        android:id="@+id/TopLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="200dip"
        android:layout_alignParenttop="true"
        gravity="center" />

    <com.google.android.maps.MapView
        android:id="@+id/mapviewHome"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:apiKey="@string/ApiKey_apk"
        android:clickable="true" />
</LinearLayout>
    <LinearLayout
        android:id="@+id/BottomLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        gravity="center" 
layout_above="@+id/TopLinearLayout" />

    <Button android:text="button" />
<!-- your buttton and other components are here --!>

    </RelativeLayout>        

Try using a LinearLayout which contains the MapView and the LinearLayout with the Buttons. 尝试使用包含MapView和带有按钮的LinearLayout的LinearLayout。 Then set the weight of the button-LinearLayout to "1" and the one of your MapView to "0". 然后将LineLineLayout按钮的权重设置为“ 1”,将MapView的权重设置为“ 0”。 Not sure if this will work, but it's worth a try... 不知道这是否行得通,但是值得一试...

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
>
        <com.google.android.maps.MapView 
            android:id="@+id/mapviewHome" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:apiKey="@string/ApiKey_apk"
            android:clickable="true" 
            android:layout_weight="0"
        /> 
        <LinearLayout 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            gravity="center" 
            android:id="@+id/BottomLinearLayout" 
            android:layout_alignParentBottom="true"
            android:layout_weight="1">
            <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
            <!-- your buttton and other components are here -->

        </LinearLayout>
</LinearLayout>

i think you have to use RelativeLayout instead of a Linearlayout.. not sure but will help you. 我认为您必须使用RelativeLayout而不是Linearlayout ..不确定但是会帮助您。

 >

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:id="@+id/header"
    android:background="@drawable/header"
     >



    <ImageView
        android:id="@+id/back"
        android:layout_width="77dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:src="@drawable/back_txt" />

    <ImageView
        android:id="@+id/gps"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:src="@drawable/gps_btn_03" />
</RelativeLayout>






<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/header"
    android:apiKey="0SQlVa3Jk1kXyql-9Bsl0kIIgN7FKV3JnG27YTA"
    android:clickable="true" />



<TextView
    android:id="@+id/sandho"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="60dp"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceSmall" />

<ImageView
    android:id="@+id/selectedlocation"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/sandho"
    android:layout_centerHorizontal="true"
    android:src="@drawable/selectedlocation" />

<ImageView
    android:id="@+id/alllocation"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/img"
    android:layout_centerHorizontal="true"
    android:src="@drawable/alllocation"
    android:visibility="gone"
     />

<LinearLayout
    android:id="@+id/layout_all"
    android:layout_width="125dp"
    android:layout_height="50dp"
    android:layout_alignBottom="@+id/img"
    android:layout_toRightOf="@+id/img" >
</LinearLayout>

<LinearLayout
    android:id="@+id/layout_selected"
  android:layout_width="125dp"
    android:layout_height="50dp"
    android:layout_alignBottom="@+id/img"
    android:layout_toLeftOf="@+id/img" >
</LinearLayout>


<RelativeLayout
    android:id="@+id/mapnlist"
    android:layout_width="fill_parent"
    android:layout_height="47dp"
    android:layout_below="@+id/header"
    android:layout_centerHorizontal="true"
    android:background="#CCCCCCCC"
     >

    <ImageView
        android:id="@+id/mapandlist"
        android:layout_width="wrap_content"
        android:layout_height="35dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/mapnlist" />

    <TextView
        android:id="@+id/smtext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <LinearLayout
        android:id="@+id/layout_left"
        android:layout_width="60dp"
        android:layout_height="35dp"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/smtext" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_right"
        android:layout_width="60dp"
        android:layout_height="35dp"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@+id/smtext" >
    </LinearLayout>

</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM