Android - Display a Map as a frame ontop of another activity - android

I have been trying to find a way to get this done but keep running into issues.
I want to be able to have a map in a frame (it does not necessarily have to be a FrameLayout, i just want it framed so it only takes up 1/2 or 2/3 the screen) ontop of my current layout and to have the current activity still displayed behind it.
In a perfect world, i would like to attach this view to a button and animation so clicking the button causes this view to slide in from offscreen left and settle in the center of my current activity, while still being fully clickable and and the map being useable (can zoom, click, etc.)
I have tried doing this with a fragment, but the issue is that the Activity i am working in is already extending another class that is absolutely necessary, so i can not extend Fragment or FragmentActivity, so i cant use fragments (unless i am missing a work around to achieve this.)
The same goes for MapActivity and MapView, cant extend the MapActivity class so cant use MapView.
Any time i try to inflate a map view or anything i get runtime errors because my activity does not extend the pertinent class. Is there a work around for this?
Does anyone have a suggestion as to how i can get this map to display the way i am looking for?
This is easily achieved in iOS but i cant seem to figure it out in Android.
Thank you in advance
EDIT
I am not looking for code, unless you have a specific example in which case obviously code is very helpful, but i am looking for an idea as to how to achieve this -- a push in the right direction if you will -- so i can write the code myself.

Solved this by adding a frame layout to my "Main" activity. That frame layout's class was set to my Map class. The Map class extended FragmentActivity and its contentView is set to my map_fragment.xml. The map_fragment.xml contains only a fragment and that fragments name is set to com.google.android.....SupportMapFragment.
After setting up my project in this way as well as setting up the correct screen layouts and dimensions for sizing purposes as well as defining a GoogleMap in my Map class, i was able to display a fully usable and interactive map over my "Main" activity.
I overrode some Activity transition animations to the Map class and got my project working 100% how i want it to.
I didnt ask for code, so i will not supply any code, but this process is pretty straight-forward if you follow the same process as i have described above.

Related

Tap Draw On a Section of the Screen?

I'm trying to make my app be able to draw with your finger like Snapchat on part of the screen but not the whole thing? Every example I have seen of drawing is just an app that turns your whole screen into the canvas and does nothing else but I'm having a hard time implementing it as just part of my app. So as well as how to just choose a section of the screen as the canvas is it possible to make another activity just like the examples that extends view that I include or can I put everything in MainActivity.java?
Yes, there is. You can create a fragment, or as many as you want, and them place the fragment(s) wherever you want in the activity by using some of the available layouts.
For example, you can use a relative layout. You can add a frame layout to the relative layout and align it in the activity where you want, set its size, and then add the fragment to it. You can check this link to learn about fragments and their usage if you don't know them.

Android Inflate Layout With its Own Activity

Good Day everyone.I have searched internet and hardly found that it can't be like that but i really can't believe.So i decided to ask here whether is it possible to inflate layout which will have its own activity i mean JAVA CLASS where i would type the code.So just for this case.Imagine we must have google maps on screen and as well as separate screen of list view people all nearby.So in that point we want to inflate the layout onto google maps view.But as i can logically think it will be horrible to write code all in one class by side of performance,so I'm looking for alternatives to inflating a layout,is somehow we can bring activity on main screen and don't lose that screen as well?This is all questions.Thank you very much beforehand!
If I have understood you right, you want to have two layouts in one Activity?
You should use Fragments for it purpose. You can add as many as you want in one Activity, and manage them dynamically. You can find solution here. Also, look at this solution.

Overlay a view in every activity

In an app I am working on, I'd like to have a bar with some controls always present at the bottom of the screen. It should overlay every activity in the app but also be able to disappear and reappear. To do this I've considered some options, such as simply using a linear layout and setting the visibility in every activity or using a fragment somehow. Probably those would work but I feel there must be a better solution. So my question is: what is the best way of doing this?
There are two ways you could do this. You could just use Fragments, and make your overlay be a fragment.
The other way would be to sublcass Activity with an AcitivityWithOverlay, which handles the overlay appearing and disappearing then have all of your activities inherit that. If I did it this way, I'd make my overlay a singleton so I wasn't creating extra versions all over the place that did the same thing.

How to communicate from Android Map Overlay to MapView

I have a problem which has been driving me mad for days - I've trawled the Web but can't find the answer to what must be a simple problem.
I am writing an Android application which uses a map to display pins at specific locations. When the user taps one of the pins I'd like to display an info window with some additional details. Simple!
I have a class that extends MapActivity (and contains a MapView) and another that extends Overlay (note that I'm not using ItemizedOverlay due to the number of pins and performance was far too slow). In the Overlay class there is a hit testing routine which determines whether the user tapped on a pin or not and if so will display a simple rectangle above the pin with the details. It all works fine but does not look that great.
I want to display a nice speech-bubble callout which in time will also contain a button or two to perform additional operations. After a lot of looking around I found this blog post and it seemed to fit the bill. The post highlights the fact that the MapView that I have placed on my MapActivity is a ViewGroup so can contain additional views, i.e. one that represents my speech-bubble callout. However, while I can follow the partial source code I'm having problems wiring it up - that's where I need some help.
I've created my 9patch image and a layout to contain it and, as a test, if I put the code in the MapActivity class then I can get the callout to display. The issue is that I need to be able to determine which pin the user has tapped so that I can get the coordinates and the associated information and this is handled by the Overlay.
So, how do I wire this up so that when a user taps a pin on the Overlay the MapActivity is called to add the new 'Callout view' to the MapView in the appropriate location with the associated text?
Update:
Well I took a bit more time to look at the sample project cited in the blog post I refer to above and now have a working implimentation. I had previously dismissed this as it was using the ItemizedOverlay but the approach was sound enough. Basically I've revised my Overlay class to accept the MapView as a parameter in the constructor so now I have access to it without having to call back down to the MapActivity. It sounds simple enough but I was trying to leave the Overlay to do what it needs to do, i.e. display the markers, and not have to tinker with the parent MapView. Fact is that it works now and I can get on with the rest of the coding.
I am not sure of what exactly you are looking for. You can find a good tutorial to figure out which point as been hit during onTap and then retrieve the overlay and print out some stuff on the map.
To display the information on fix location you could put all your info components in place in your xml with visibility invisible and change it to visible if an overlay has been touched.
Hope this helps,
Stéphane

Opening an activity within a View in Android

I've recently started developing Android Apps, and whilst the model is making more sense the more I look at it, I cannot do something (nor find any reference material on it) which to me seems quite simple.
I have an activity which has five buttons along the bottom, and a blank View taking up the rest of the screen. I want, upon clicking these buttons, for an activity to be opened in (and confined to) this view. I can get a new activity running without incident, but this opens in a new screen.
If anyone can show me an easy way to launch a (sub/child?) activity within a view which is defined in the parent activity's layout xml file - equally, it could be created in the parent activity - you'd really be doing me a favor!
I'd recommend taking a look at TabHost. The tabhost is an Activity itself, and the sub-views are all Actvities as well.
Here is a good tutorial that'll get you going very quickly. There is a more work to create (optional) icons for the tabs (also describe in the tutorial).
Hope this helps.
Edit* You mentioned buttons being at the bottom of the screen. Take a look at this SO Question
You can achieve that by using an ActivityGroup... here is a simple example which shows how to do it using a TabActivity:
http://web.archive.org/web/20100816175634/http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/
Of course, you will have to change the code since you are not using TabActivities. Just take a look at the getLocalActivityManager and getDecorView methods that is what you will be using.

Categories

Resources