My purpose: I have a RelativeLayout acting like a button (clickable) and it has multiple views inside of it: TextView, Image. I want to transform this RelativeLayout alltogether (as if it is like a single object) in 3D coordinates.
What I know: I know that by using Camera and modifiying Matrix, i can really transform an Image view in 3d.
However, i can't do this on a ViewGroup like a RelativeLayout as i can't modify it's matrix.
Question: Is it possible and if yes, how?
Well android isn't built to work that way, each view in android is responsible for drawing it self, so you can't just put a certain render logic in a parent view and expect the child views to cope with it.
Easiest thing I can think of is to create your own big view and draw your child views manually inside it, then I believe you can achieve the desired effect by using the camera object with your canvas.
Or you can go openGL but that would only make sense if you have performance issue in the above approach
Related
I want to make a view that looks like a weight scale, like the image below:
For that I thought of using a horizontal scrolling RecyclerView with view holders representing each value of the scale and that works fine, but I can't figure out how to make it curved or if it's possible. I want it to be curved to look more like a weight scale. Does anyone know how I can manage to do that?
I'd say don't go with RecyclerView. It's not intended to be used for such purpose and it might be very time consuming to make it work. I think that the best way is to write a view from scratch. You can draw the scale manually using onDraw(Canvas), simple math and a bunch of drawing operations. The most difficult part would be to add a scroller to get the fling gesture working nicely.
My idea is to have two surfaceViews. One surfaceView which will hold an image (say ImageSurgaceView) and second surface that lie on top of the first one which holds the annotations (say AnnotationSurfaceView) like circle, rectangle etc. Now I have to map these surface views such that the height, width are same and moreover, both the surface view should move on drag i.e share the touch events. To be precise, when I move the image up the annotations should also move up.
Now, I am not sure if this is possible in android. Can any one tell or share some info on this. I don't have any implementation idea to this and hence I don't have any specific code. Moreover, I couldn't find anything similar.
Thanks for helping.
Yes, this is possible. You can add both SurfaceViews as children of a FrameLayout. You will also want to call setZOrderMediaOverlay on one or both of your SufaceViews in order to specify how they are layered.
Furthermore, this could be a graphic intensive algorithm you are describing. Consider adding the AndroidManifest.xml application attribute android:hardwareAccelerated="true".
Finally, just set up a custom OnTouchListener to handle drag events. Use MotionEvent.getRawX() and MotionEvent.getRawY() to get the touch point, and use this to manipulate the canvases.
I've been working on this for a while but can't find anything that exactly addresses my question (at least not something easy to understand).
I have a main layout XML file where I define various layout objects like a Button or a TextView (and I know I can add SurfaceView, View, and view and other things too). I want to draw a shape (in my case it's an arc) in just one of these objects so it doesn't take up the whole screen and so I can position it relative to other things.
(In my case it will ultimately re-draw the arc kind of like a circle with a gap in a different position every time I call a method depending on a value I pass to the method, but that's separate from my basic question.)
I know the answer will have something to do with a canvas, an onDraw method, maybe Paint, probably a view. I have been able to draw a circle from a custom View object by setting the main java file's layout as that View (as opposed to R.layouts.main), but that takes up the whole screen, and I'm unsure how I might be able to have that dynamically draw with modifications.
A really clear explanation or better yet an actual example would just be awesome.
As i see it u need to draw a specific shape on widget and not on complete screen. Try using layer List.
you can refer this link for sample Link
I'm trying to overlay several images[to form a building plan with possible zoom].
The point is to choose which images to averlay each time depending on selected filters[staff, equipements ...].
After doing researches, I implemented the zoom using a WebView but I didn't find a way to make this webview take different images at once [which is possible with ImageView using LayerDrawable].
Is there any way to achieve this ? or should I just stick the ImageViews and find a way to implement Zoom in it ?? I hope my question is clear and not too stupid since I'm just a beginner :).
Thanks for your help!!
While you can stack several ImageViews on top of each other, if you want to make this efficient and feature rich (pinch zoon, panning) you need to create your own component, either based on View or based on SurfaceView.
Personally I think SurfaceView is an overkill here, subclassing simple view should be sufficient. You need to manually draw your layers from bitmaps on canvas on onDraw() method of the view.
Then you can use GestureDetector or ScaleGestureDetector to add zoom by scaling your canvas via affine transformations.
Use a RelativeLayout for starters.
You could use the ViewGroup.addView(View child, int index, ViewGroup.LayoutParams params) or a variant along with ViewGroup.removeView(View view) or ViewGroup.removeViewAt(int index).
This would obviously require you to inflate the views manually using LayoutInflater but you could keep a global reference to each after inflating and just flip between the two
In Android 2.2, I want to display a few sprites and clickable animations over an existing view. I just discovered that SurfaceView cannot be transparent
I tried overriding dispatchDraw() of a LinearLayout but that doesn't seem to be callable via a Runnable Thread.
I also tried to extend Canvas directly, but that quickly turned into a mess when trying to place it in my XML layout.
Do I have to use GLSurfaceView to have a drawing view whose background is transparent?
Optimally, I'd like to just have a Canvas on which I can draw Bitmap at various coordinates, instead of dealing with the details of GL (unless GL is the only way I can do transparency).
Silly Rabbit. Just use Views and move them around wherever you want within a FrameLayout. SurfaceView is not designed for what you're trying to do.
I'm going to try Switching from Canvas to OpenGL and toss in parts of TranslucentGLSurfaceView.
I'm still open to selecting an answer that doesn't require OpenGL, just for the sake of it solving my original question.