how to show TextView,Buttons On MapView (To Overlap On It)..? - android

In my application i have mapview and I want to show distance in a textview and also a Button ,
I have done this.and tried this..
http://www.anddev.org/post3452.html#p3452
PROBLEM IS>>>>
I WANT TO SHOW TEXTVIEW AND BUTTON OVER THE MAP VIEW..
so I can See MAPVIEW in Full Screen..with other items over it(as we can see map through textview)..
Any SPECIFICATION NEEDED TO BE DONE IN xml FILE..??
Please..Reply me..
Thank You..in advance

Yes you can do that.
For eg:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="#+id/mapView" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:enabled="true"
android:layout_centerInParent="true" android:clickable="true"
android:apiKey="your api key" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Click"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" android:id="#+id/clickBtn" />
</RelativeLayout>

create a layout with the RelativeLayout and embed the map view in it. Once set, set the relative position of your components as per your need.

Related

Add a view overlay on map view android

I am using the MapView from the Google Map Android SDK in full screen, but I have a requirement to display another transparent full view over the mapview. The overlay displays as expected, however, the map can be controlled (markers can be clicked, map can be moved) despite the overlay being on it.
How can I ensure the overlay prevents the map from being controllable when in view?
Add following on your overlay view parent layout.
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
Remember you need to place above line on parent layout of overlay view
You can do this by making your overlay clickable. Add below code to the xml of your overlayview.
android:clickable="true"
For example I use the following code to add a button to the page
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="#+id/location_map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#359c5e"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:padding="8dp"
android:layout_margin="5dp"
android:text="#string/go"
android:textColor="#ffffff" />
</RelativeLayout>

How use the mapView in activity?

In my application am use include other layout to include two view in main XML,in that first view have simple text view only and in second view i have map view.In my main XML file i have two buttons when i click first button to show first view with text view,when i click second button i want to hide the first view and to show second view with map view.I don't know how to show the map view in main activity.Can any one know please help me to solve this problem.
Firstly tell what version of google maps do you use
v1 - https://developers.google.com/maps/documentation/android/v1/
v2 - https://developers.google.com/maps/documentation/android/start
Usually what you need to do is to put you two layouts inside FrameLayout and show/hide one of them when you click on particular button. But to be more specific we need to see your code.
1) MapView is used by GoogleMapsV1. But it needs an api key provided by google for individual developers upon registration.
Unfortunately, which is closed by google and you have to use GoogleMapV2 with new V2 key.
Also, workout with fragments because, here we are using Fragment or SupportFragment.
2) You can use a FrameLayout inside which your two overlapped views with id's. So that you can show or hide views at same position as you need.
Please try to use bellow code.
<LinearLayout
android:id="#+id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2" />
</LinearLayout>
<ViewFlipper
android:id="#+id/viewFliper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/buttonLayout" >
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="your map key map_key"
android:clickable="true"
android:enabled="true"
android:focusable="true"
android:focusableInTouchMode="true" />
</ViewFlipper>

Android Button Layout - Not Displaying Correctly

I am trying to get three images to display on the "welcome screen" of my Android app. Only one of the images is being displayed, and I cant figure out why... any Help?
XML File:
<?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"
android:gravity="center"
android:background="#drawable/main_bg"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:paddingTop="30dip"
android:layout_height="wrap_content"
android:gravity="center"
>
<ImageButton
android:id="#+id/mnwvbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dip"
android:background="#drawable/mnwvicon" />
<ImageButton
android:id="#+id/reportsbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/reportsicon" />
</LinearLayout>
<ImageButton
android:id="#+id/mnwvshowbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/showicon"
android:paddingTop="30dip" />
</LinearLayout>
I have the exact same set up in another app, so I dont know why it isnt working here??
I think its because the last image is outside the inner linearlayout so put it inside the inner linearlayout and you should be able to see all three images in a row.
Try scaling the images using the attribute android:ScaleType="centre" inside the ImageButton
or try a different layout like Tablayout for arranging the images in rows and columns with proper spacing.
Sorry guys. I didnt have the app support the different screen sizes. I am not sure why this mattered, but once I added support, then it worked perfectly!. Thanks for your input though! Anyone know why this mattered though?? I dont know why supporting screen sizes matters?

How to display a floating icon on mapview?

I would like to display an icon in mapview just like the "change to list view icon" displayed on Google Places program. any clue how to do that?
If you need to put an icon in a relative place of the screen you can merge the mapview with a relative layout (in the XML page) some thing like this:
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="xxxxxxxxxx" />
<RelativeLayout
android:id="#+id/rl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/icon">
</ImageButton>
</RelativeLayout>
</merge>
Or if you need to use an icon over a map coordinate that you specify then you need to define an overlay.
hope this helps :)
What you want is called an Overlay. Check out the Google Map View tutorial under Part 2.

How to put button on webview

I want in background I will show an webview. and on that webview on foreground i want to place another button. How to achieve the same. I can load the googlemap using map view. but unable to place a button on it. I am showing google map in an mapview.
Thanks
Thank you all. I got the solution by using Framelayout.
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/header"
android:layout_above="#+id/footer">
<WebView
android:id="#+id/GD_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/footer" />
<Button
android:layout_centerVertical="true"
android:id="#+id/setTimeBtn"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:background="#drawable/settime"
android:layout_gravity="bottom"
android:layout_marginBottom="15dip"></Button>
</FrameLayout
>

Categories

Resources