Apparently XDA thinks my code is a link to an outside website ??? so it's attached in a .txt
Here's my problem. I finally figured out how to get my custom view
working, but discovered that "canvas.drawCircle(..)" draws based on
the screens dimensions and not the bitmap drawn to the canvas (I may be
misusing some terms/concepts here, still a little iffy on the whole
custom view).
Basically, I have a bitmap of a map image (decoded from a .jpg resource), and I want to be able to draw relative to the bitmap's pixel dimensions, and to the bitmap if possible, so that when it's panned/zoomed, it stays in its respective
place. Here is the code for my custom view. I x'd out my latitude and
longitude. The touch handling is code adapted from a Hello, Android
(3e) excerpt.
I'm currently working with "MAP" mode, but it will also come into
play for NAV. But I basically need to draw relative to the bitmap, which is
scaled and manipulated through the canvas(?) so that the current
location dot will stay in the same spot when the bitmap is panned or
zoomed, instead of staying in a static location based on the screen's
dimensions. Any advice?
-Mike
Related
I am pretty new into android development and have a couple questions I'm sure you guys can answer pretty quickly but have so far not been able to figure out. How do I have a set background in a live wallpaper besides just creating something from canvas, I have it already loaded in the hdpi I just need to figure out how to call it. Also, is it possible to have something appear enlarge a little bit in the center of the screen then fall off the screen? I'm trying to create a time lapse of a tree where it goes through all the weather changes. Any sites you could link me too or answers you would have would be greatly appreciated. Thanks for anything you guys are able to do.
Can you be more specific? When you say background are you talking about an image file you've added as a drawable?
If you use the drawBitmap method you can draw images anywhere on a canvas.
This is roughly how I do it on my Live Wallpapers.
Code:
Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.background);
c.drawBitmap(background, 0, 0, null);
That will draw the bitmap at the upper left most position on your canvas.
If you want your live wallpaper to slide left and right as you swipe between home screens you need to adjust the x position based on the offset. Look at the cube live wallpaper source code for more information on how to get the offset value.
What I have is a picture loaded in the hdpi file that I want to use as my background, the thing with the cube is it shows you how to draw a picture but not add one into it. I want to load in the photo and then have objects enlarge and drop down around the center of this picture. The design I'm going for is a time lapse of a tree. I was told surfaceView can set your background but I'm not sure if that's the case or not. Thanks for the reply though I appreciate it.
bearcatext said:
the thing with the cube is it shows you how to draw a picture but not add one into it.
Click to expand...
Click to collapse
It works exactly the same but instead of using c.drawLine() you use c.drawBitmap()
That makes a lot of sense thanks, and for the leaves falling would you just set the coordinates to somewhere in the middle then? Also, is there a way to have an image change color mid-screen so it looks like fall is hitting? Thanks for all your help again though.
Hi guys, I need to convert the lat/long coord to pixel xy coord to show a dot on the top of some image, I know I can use the following code inside MapView to do that conversion:
mapView.getProjection().toPixels(location.getPoint(), screenCoords);
int x=screenCoords.x;
int y=screenCoords.y;
however, I don't want to show or use the MapView, I just want to extract the X and Y screen coord, because I have my own background, my app will use a simple ImageView to display that background and I want to draw a little dot on canvas, on the top of that background, that dot will only appear if that location respect some range.
To better understand the question, imagine I have an aerial photo showing some building, I know the lat/long of that building, and I want to display a dot representing the building and a second dot if my actual position is near from that local.
How I can get the XY pixel screen position of that location without showing the MapView?
Hi!
I have a problem with my Maps-application. I have the mapview in bottom in my layout, and above that a semitransparent image to give the map a specific look.
I also have a location overlay and another image overlay to mark out some interesting positions. The problem is that I don't want the semitransparent image to affect my overlay markers. They seem to be drawn directly on the map by default.
Is there a way to change something somehow so that the markers will be drawn above the semitransparent image (if they are visible on screen of course)?
Since SDK 4.2, Google has a way to retrieve the dimension of an existing appwidget. You can use the bundle in onAppWidgetOptionsChanged callback to retrieve the upper and lower bound of the widget. But I need to scale a bitmap precisely to fit the widget. Anyone knows if it's technical possible in existing SDK to get the pixel-correct dimension of the appwidget?
What's more, I found that the stock launcher in JB (as well as Apex) returns incorrect values for the upper and lower bound. For example, if the widget is in portrait, it may return a rectangular dimension in landscape. Nova, however, doesn't has this issue.
I am making simple ball game and l have problem.I can't change position of Ball. I tried:
1. SetX() and setY() but lower APIs aren't supported.
2. Params and margins but when I move it left or right, the whole activity content is moving with it. Up and down moving is working fine. (Activity will have 10 ImageViews)
3. Android animations - Problem is that I can't get coorinates (getLeft(), getTop()) during the animation.
4. Canvas and draw elements - I change position of image with onDraw() and invalidate() functions but when I but backgorund and all other images (as bitmaps) it is very slow.
Can you give to me any ideas or suggestions? Thanks in advance.
Can you post the code? What do you exactly want to be done, there can be many different "ball games". You want to change the position of a bitmap or circle on the screen create x and y variables, draw bitmap or circle using them and if they change, the object will be drawn elsewhere