Android - How to overlay images in a WebView? - android

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

Related

Android: Is it possible to have two surfaceview on top of each other?

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.

Is it possible to use android.graphics.Camera on ViewGroup?

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

Alternative to AbsoluteLayout

the question "What is a usefull alternative to AbsoluteLayout?" seems to be a question which is often asked, but never really answered. My situation is as follows:
I want to position Circles (for the sake of simplicity i used RadioButtons for testing) so that the distances between the circles are proportional on all possible display sizes.
Also i need to know the position of the circles to match onTouchEvent.
This seems fairly easy with AbsoluteLayout since i can get (at runtime) the defaultDisplay's width and height and so i can position Objects in an AbsoluteLayout relative to the display metrics.
Now I want to avoid AbsoluteLayout for obvious reasons, but RelativeLayout doesn't seem to be an alternative since - as far as i know - one can only say "put that object right next to that other object" or below or whatever. How to fix this?
In my Opinion the best way to achieve your goal is to use the Canvas and draw everything yourself. In the Canvas you have the information of the screen at runtime and you have full control of the things to draw.
If you only need to draw your own shapes (and handle all normal touch events) and do not need other UI Widgets on the same view, then use Canvas.
If you do need Widgets on this view then your only option is AbsoluteLayout.

RelativeLayout create button at a dynamic position

I am working on a project that involves painting on images.
To delete the unwanted lines or curves i have to draw a border and X button to delete it.
I have a relative layout where i have the freehand drawing canvas. on edit mode i should make them as u see in the pic, where i have to create button on a varying x,y positions.
i am confused how to achieve this.
Thanks in advance.
Jana.
I suggest doing this manually rather than using the Button widget. Override the onTouchEvent on the view holding your painting and use MotionEvent.getX and MotionEvent.getY in combination with MotionEvent.getAction to determine behaviour when the user touches the 'button'. Skipping widget creation will improve performance and open up doors to other types of functionality.
You could use the deprecated AbsoluteLayout container for this or keep the RelativeLayout and use layoutMargins to set the location of the buttons. The former is the route you should take despite the container being deprecated as the later breaks the layout paradigm by misusing margins...
You should keep in mind that there are a variety of devices with different screen sizes and setting explicit, pixel based locations is going to be awkward.

Display ImageView in SurfaceView

I am currently attempting to animate some images in my SurfaceView. Right now, I am displaying my images as Bitmaps. However, I think it might be better to implement these Bitmaps as ImageViews. I have not been able to create multiple ImageViews on my SurfaceView (I am trying to not do this in XML, as I want to get things working first and then later change things around so it is more portable). Is there a tutorial somewhere on how to do this, or am I like wayyy off and should just stick to Bitmaps??
You generally shouldn't try to mix View objects and SurfaceView. SurfaceView is a very special view that provides direct drawing by essentially punching a hole in the current window. It seems better to stick to bitmaps.

Categories

Resources