Overlay a static image on a MapView - android

I'm still a newbie to Android but have searched high and low for an answer to my problem without success.
I have a map view that the user can fully manipulate (scroll, enlarge etc.) but I need to let the user know where the midpoint of the map is. I want to use a small "crosshair" image for this and display it at the centre of the map AT ALL TIMES and AT ALL LEVELS OF MAGNIFICATION. In fact, I just want the image to remain on view at all times. Can I find a way to do this? Can I hell!
I'm sure there is a very simply solution to this from one or two of you gurus out there. Please help.
Tony

In your layout file that contains the MapView, make sure that the Layout container is of type RelativeLayout. Then simply add the ImageView as a child of the RelativeLayout, with an attribute of layout_gravity="center"
Basically, research RelativeLayout.

Related

Android - ImageView as Offline map

I am trying to implement an offline map content into my android app. I need not so much detailed map just for a specific area and mark some places over it. a zoomable and scrollable image seems to be enough for me.
First question is;
1-) what is the best option for offline map in android? My constraint is that my app couldn't use any internet connection. Do I have to use an imageview (by adding button markers on it) or can I use any offline data for Mapview?
I have searched a lot for using imageview as map but couldn't get so much result.
my basic question for imageview is;
2-) How can I add a marker(a button) on a specific position of imageview?
I have found some sample code for scrolling and zoom and implemented them (Scrollview has no diagonal scroll as default) but I couldn't find a way to add marker to an scrollable, zoomable imageview.
Please don't think on sample code, just assume that imageview is in an scrollview and I try to add a marker(button) on it.
Thanks in advance
There are other options such as OSMDroid: But personal experience of this library would recommend using an imageview if you can and don't require zooming in and out and having performance issue.
You can have a scrollview, containing a horizontal scrollview, which can then contain a relative layout with an imageview taking up the space. Then add the markers to the relative layout and position accordingly.

Specific Parts of ImageView clickable

What are some ideas about having an ImageView that takes up the whole screen and making only parts of it clickable? I was thinking that I could extend the ImageView class and override its ontouch method which would allow me to detect touches based on an x and y. The only problem I can see with this is on different resolutions the touches might not map to the correct areas. I suppose I could then detect the resolution and figure out some way to map the x and y to the correct areas. I feel like there must be an easier way though. Does anyone have any other ideas?
How about creating transparent views with your desired click listeners on top of the ImageView using a RelativeLayout. You can use the xml to place those "hotspots" where you would like them relative to your image and define the layout so the "hotspot" view scale properly along with the image when displayed on different resolutions.
If the 'hotspot' shapes are not too complex, you could dynamically split the image, setup individual clicklisteners and re-merge the drawables in a way for them to appear contiguous. I do like Gregg's method more though.

Android Layout On Top of an Image

I am struggling with a Layout Problem on Android. This is very simple to do on the iPhone, but with the various screen sizes and the Layout classes available. I am having a hard time doing this.
One thing that I have noticed is that setting backgrounds on objects in the xml really messes up the layout on the device. I generally have to put in a FrameLayout and an ImageView to get a background.
So Am trying to get to this. http://www.calidadsystems.com/images/AndroidListItem.png (Sorry I don't have enough pts to post the image)
his is a status view and is an item in a List View. There are 8 TextViews that need to be set. Each of the 222 fields will change. The current background has the colors in there at specific locations and I am trying to line up the Labels and TextViews to get the picture below. I built this one with AbsoluteLayout which is deprecated, but it also does not work very well on the device.
I have constantly struggled with the layouts on Android. Does someone have some good sample code that could do this?
You're probably going to want to use a RelativeLayout. You can use the android:layout_alignTop="id" attribute to make the rows be in line correctly. And android:layout_alignLeft="id" for the columns. Other than that its just a matter of playing with the android:layout_marginLeft="XXdip" attribute to get the space between them how you want it. Check out this page for an overview and examples of all of the Layout types. Here is some more sample RelativeLayout code. And one more page with another example. RelativeLayout is a bit tricky to get used to but once you've used it a few times its pretty easy to understand and get the Layout that you want. The benefit of it is that your UIs look nice on several different screen sizes when you define them this way.
Why not just composed the layout in a table layout and set the table layout's background to a custom made graphic you make? This should work well with you. Specifically the design of your design would be like 4 columns with x rows. Then using the strechcolumn property, you should be able to accomplish what you are trying to do!
If you scale the graphic properly, then you shouldn't have this problem overall.

Android Layout Fill_Parent Problem

I am fairly new to android and am having some problems with a layout. Below is an approximation of what I want the layout to look like. (I would like the list to be below the screen at first so that the user can scroll down to see it.) However my code as it currently stands makes all of the views on the left only take up a quarter the screen instead of half, as depicted, even though I have all widths set to fill_parent.
Also, this layout seems to mess up the coordinate system on my custom view. Normally this wouldn't be much of an issue, but in this case I am using that view to draw a picture and the picture ends up in the wrong place. Does anybody have any idea how to resolve these issues?
Could you show the XML file you are using? This would be helpful. Also, the coordinate system of a View does not change based on the layout.

Android - how do I place an image on top of my existing layout through code?

I have a layout in which I am displaying a webview. I want to add images on top of the webview at specific places through code.
Can some one please tell me how to do that?
The translucent background example in API Demos makes the view cover the whole screen. I want to place only a small image and at a specific location (origin not 0,0)
Thanks a lot.
Have you tried putting both the WebView and the ImageView inside an Absolute Layout? This should let you specify the X/Y location of your image and by ordering make it constantly drawn over the webview.
EDIT: check out the Absolute layout:
http://developer.android.com/guide/topics/ui/layout-objects.html#absolutelayout
AbsoluteLayout is deprecated and if that bothers you, you may want to look for alternative.
I have put an example in my blog post here. It might not be exactly what you are after, but should give you an idea:
http://anothermobiledeveloper.blogspot.com/2011/10/using-relativelayout-instead-of.html

Categories

Resources