How to animate Bitmap on Surface view onDraw()? - android

I am trying to make a game. I try to use GridView but wonder how can I drag Item onTouchEvent(). I found an example
http://www.droidnova.com/playing-with-graphics-in-android-part-ii,160.html
It is a great example. I cropped my image in 12 small image bitmap. display them on screen randomly on specific position.
By overriding the onTouchEvent() I got my requirement. Now I want to animate my image as the "swap" other image by animating. I have both images X,Y location.
I am wondring if it can by done by some Animation class.So that I should not put effort for doing it manually. I know it is not a hard job. But I Animation class can do it more smoothly.
So I have a ArrayOfImages(Bitmap) and I want to swap 2Images with animation. I am using a thread that update "Canvas" in background. Please help me.
.
I more thing. How can I add Scroll view with surface holder?? Is it possible? Because I think when I try to drag my image , It my not drag and active scrollbar for this response?

Finally I am using a loop for a specific x,y to a specific x,y while updating the canvas. Although this is not a efficient way.

Related

Panning a layout with imageviews on it

I have been puzzled by how to approach this for a while. I have Framelayout with over 20 image views on it. I want to be able to pan the framelayout. Basically, touching and dragging causes the background image to pan (and the 20 image views to move along).
This is similar to what strategy games do (you have map and buildings).
I read all about panning and zooming and they all talking about doing this for single imageview. In my case, not only it is a layout but also it has other views.
How do I approach this? Any pointers ?
Thanks
I have a github project for zooming and panning although its for View Groups it would be easy to change for a View.
Check it out let me know if you have a question it is unfinished but works.
https://github.com/Xjasz/AndroidZoomableViewGroup
Copy the class and extends FrameLayout instead of ListView.
Then make sure in your XML to use the class instead of a FrameLayout.
You could have a TouchInterceptor/Custom view where on touch, you offset the view from its parent by the delta of the current touch coords from the last touch coords.

android ImageView vs canvas for game

I´m new in android development. I want to create a game where the user needs to quickly drag and drop balls with the finger in the screen to specific locations in order to win.
I don´t know if i can do this with simple ImageViews or i need to use canvas or other thing to draw in the screen.
I have tried to drag and drop an ImageView on top of another ImageView but it does not seem to work very well and i'm hesitating if i need to do it drawing figures instead of using the ImageViews or to do something else.
Please advice. Any help is apreciated. Thank you.
ImageViews are Views designed to hold image drawables, which isn't really needed in your case - you can use a simple View with a color background or implemended onDraw method, you can use an ImageView just as well.
Asfor the drag and drop, what you need is any View with implemented onTouch method so that the view changes its position on screen with ACTION_MOVE touch events.
If you're interested, i have implemented a simple frame layout with drag and drop functionality. My layout requires long-click to start drag, but it can be easily modified so it won't. Check it out at my github page. You can clone the project and run demo activity to see how it works, and start from there.

Zoomable Imageview or Activity

I have an activity that has just a image to show like graphical help. It has a lots of info and needs to be zoomed. I searched alot in diffrent sites and they say imageview is not zoomable. and i found complicated algoritjhms for it. i want to make my programm to zoom like many usual proggrams that zoom like my 2 fingers get further image zooms in and if they get close zooms out and and i want to user be able to move postion if image in image view bye moving his finger on it.if its impossible can i make that as background and do these functions on whole activity? thanks for helping
This SO thread should have everything you need to implement the pinch zoom. Alternatively you could have a look at the PhotoView library; an implementation of ImageView that supports zooming.

Android: Draw a moveable and sizeable rectangle on ImageView(Or any other bitmap compatible widget) and crop the selected region

I want to crop my image which is being displayed on an ImageView. How I want to go about it is that I want a re-sizable rectangle to be displayed on the image. That rectangle will have moveable corners (which I can drag around with touch) to increase/decrease its size. The image below illustrates a demo of something I would like to develop.
P. S. I am not quite sure how to phrase my question.
What I want:
http://imageshack.us/photo/my-images/832/customcropbox.jpg/
The final solution I came up with after ample research was:
Extend ImageView to make my own custom view.
#Override onDraw method and do my custom drawing there in that method.
Implement onTouchListener on the view to get the touch events and process them according to their position.
e. g.
I checked whether the touch was in the radius of the anchor point circle I drew around the movable rectangle that I was drawing in my overriden onDraw method.
Edit:
I am sorry guys I don't have that piece of code anymore, I came here after a very long time otherwise would have loved to help you out.
Heartache.

Android - Transforming widgets within transformed widgets and the resulting usability issues

I'm new to Android application development and I'm currently experimenting with various UI ideas. In the image below, you can see a vertically scrolling list of horizontally scrolling galleries (and also textviews as you can see). I'm also doing some matrix and camera transformations which I will come to in a minute.
For the background of the list elements, I use green. Blue is the background of the galleries, and red is the background for the images. These are just for my benefit of learning.
The galleries being used are extended classes where I overrode the drawChild method to perform a canvas scale operation in order for the image closest to the center (width) to be larger than the others.
The list view going vertically, I overrode the drawChild method and used the camera rotations from lack of depth dimension in the canvas functionality. The items in the list are scaled down and rotated relative to their position's proximity to the center (height).
I understood that scrolling and clicking would not necessarily follow along with the image transforms, but it appears as though the parent Gallery class's drawing is constrained to the original coordinates as well (see photo below).
I would love to hear any insight any of you have regarding how I can change the coordinates of the galleries in what is rendered via gallery scroll and the touch responsiveness of said gallery.
Images in the gallery are not same dimensions, so don't let that throw you in looking at the image below
Thanks in advance!
Ben
link to image (could not embed)
-- Update:
I was using my test application UI and noticed that when I got the UI to the point of the linked image and then I touched the top portion of the next row in the list, the gallery updated to display the proper representation. So, I added a call to clearFocus() in the drawChild method and that resulted in more accurate drawing. It does seem a tad slower, and since I'm on the Incredible, I'm worried it is a bloated solution.
In any event, I would still appreciate any thoughts you have regarding the best way to have the views display properly and how to translate the touch events in the gallery's new displayed area to its touchable coordinates so that scrolling on the actual images works when the gallery has moved.
Thanks!
As I updated earlier, the issue of the graphics of the gallery not fully refreshing was resolved by calling clearFocus in drawChild method for the ListView extending class.
The problem with registering the touch events turned out to be where I had used an example for the basis of my experimental program which called a pre-translation on the matrix used for painting. Once I removed that call and adjusted the post-translate call to compensate not having the pre-translate call any longer, I was able to scroll through the galleries regardless of their position, size or rotation (around x axis).

Categories

Resources