I want to have 2 views. My first one will be a GoogleMap and then in the four corners I want to add some graphics. I want when the users moves the map the images to stay in the four corners. I coouldn't find any tutorials on that and I do not know where to start searching so if you have any links or any proposal on what to do, inform me and I will come back with code.
extend the MapView class and override the dispatchDraw() method.
It gives you a canvas and you can draw on it as you please. Afterwards just send it to super() and you have what you want.
Propably you could use an overlay class. You can find many tutorials on overlay with Google. And just position the images like you want.
Related
So here is my problem. I've spent couple of days on this and didn't get anywhere. I've tried every layout possible, but it just doesn't seem to work.
Basically, I have a map of a floor and I want to make it so when you click on different parts of that floor, a new activity or a dialog box shows up. I want this to scale for all the devices. Why is this so difficult in Android? I would think that putting buttons on top of an image would be easy and made sure that it wouldn't move like in HTML.
I have been looking into Surface View, but wasn't sure if that's the best way to go? I can get the coordinates of the objects on the floor, would that help?
I want to implement this inside of an fragment. Thanks!
One possible solution could be to have a RelativeLayout as the base layout of your 'Floor Map' fragment, with the floor image set as its background.
Then you could add buttons or any other views to the Relativelayout at the coordinates of the objects.
If you already know how many features the floor will have, you could add the buttons statically, otherwise, loop through your array of features to add them dynamically.
I have app consisting of RelativeLayout, TableLayout and some buttons. Now I would like to draw a circle under point where user pressed on screen. One way to go is to extend View and add all the functionality inside, but I am wondering if there is any more elegant (general) solution?
I was thinking in way of transparent overlay, which you add to layout and it captures MotionEvent, draw circle on point of touch and passes event to underlying View component (so buttons are still clickable).
That way solution would be more reusable, as you can easily plug it in any project, but unfortunately I have no idea if it is doable that way. Any hints?
I'm pretty sure you can achieve what you want using GestureOverlayView.
Resources and examples are available:
http://developer.android.com/reference/android/gesture/GestureOverlayView.html
http://developer.android.com/resources/articles/gestures.html
http://www.vogella.de/articles/AndroidGestures/article.html#example
I dont know if my suggestion is the best solution,but I would do the following:
Create a new class that extends Drawable.
Override the onDraw method and in there draw your circles on the canvas.
Add a. addCircle(int x, int y); method to the drawable class which you will call each time you want to add a circle.
Then in you activity create a new objectof the above mentioned class and set it with context.getWindow().setBackgroundDrawable(your object) as your WindowBackground. Then where you handle your motionevent call this objects .addCircle method and your circle will be added.
Like this in your activity will be only several lines of code and it will be reusable.
I'm trying to add some arrows to the screen to indicate if there are items available to the left or right so that the user knows to scroll.
Initially I just added these images into the instantiateItem function in the pageradapter. However I want to animate the arrows so that they fade in and out and disappear when the user touches the screen.
I've started to think that I may be best off extending the viewpager class so that it always displays the arrows independently of the adapter. I've looked through the code but can't see a place where I would add the overlay view.
Has anyone got any ideas?
Thanks,
m
As suggested by CommonsWare
You might wish to take a look at github.com/JakeWharton/Android-ViewPagerIndicator and see how Jake did it.
this information lead me to the solution.
Hi
I am searching for functionality which works like the itemizedOverlay on the mapview, only for Imageview. So that I can add items on specific locations on the image and trigger actions on tap of the item.
I am building an application for Android where you get Floorplans and on this Floorplan the rooms should be marked and clickable to get more information.
Thank you very much for any help or hint in this matter
Use a RelativeLayout or FrameLayout. Both support Z-axis ordering -- later children will appear to float over top of earlier children. Use setOnClickListener() to be notified of taps on the items.
I have a conceptual question to ask:
I created a custom dialog (extends Dialog) and I want to draw a chart (dynamic data, not static) in the top third of the dialog.
What's the best (only?) way to approach this?
A) Get a canvas to the dialog and draw to it? Seems like I need access to the dialog's draw, yes, or can I do this outside of the draw?
B) Subclass a view within the dialog layout (e.g. LinearLayout) and override it's draw and draw the chart?
C) Other? I've read that one approach would be to draw to a bitmap and then blt (or equivalent) to the canvas. This sounds closer to what I want to do, as once I create the chart, I have no need to alter it (no direct user interaction).
I haven't yet found any good sample code that deals with custom drawing in a dialog, so if I'm missing something, an example would be great.
Thanks much,
Rich
Solved.
My solution was a hybrid of B/C above. Since I needed access to the view's draw() method, I created my own subclass of an ImageView (e.g., MyView).
From within the draw(), I can get the dynamic size of the ImageView as it appears in the dialog. Given the size, I can now perform draws scaled to the custom ImageView size within the dialog.
I had to remember to use the proper custom view XML syntax in the dialog layout (e.g. "com.avaliant.dialogtest.MyView" to replace "ImageView"). And, of course, in my dialog class, I had to set to view to the proper view class:
MyView test = (MyView)dialogView.findViewById(R.id.test);
Quite easy once I understood WHY I had to do what I had to do :).
Rich