Cut hole in (any)layout, that shows the underneath layouts - android

What I want to achieve is this
sample
basically there must be 2 layers where the one on top needs to have a hole on a specific location, with a specifc radius, that can show the underneath layout. Moreover, the hole can must be able to be resized (scale animation).
The best thing I've found is a proper library (https://github.com/amlcurran/ShowcaseView) but looks limited and I don't want to import a library just for that. Another solution could be to add a custom shape and add it as a background to the top Layout (the problem with that solution is that I am not able to move the shape and to set the position/size). Or I could have a canvas and draw over it but looks overkill.
Is there an easier component to I use in order to achieve this result?

Related

Multicolored android slider

I want to create this type of slider
I don't want the code but the directions. what is the best thing todo this?
is there any similar library project available?
is there any similar view already available natively.
is this more easy to create in jetpack compose UI.
Thank you so much for your help.
Since you refer to the view you want as a "slider", I assume that you are thinking about using something from the Material Design library. My personal experience with the Material Design views are that they primarily enforce the MD guideline and are not very flexible although they may work for you in this case.
is there any similar library project available?
As for libraries, it looks like the other answers point to some that may be capable of what you are looking for.
is there any similar view already available natively.
I suggest that you take a look at using a SeekBar not because I think that it is necessarily better, but I believe that you can get the result you want with a little effort that would not have external dependencies other than the standard libararies.
Here is another answer of mine that explains how to build a SeekBar similar in structure that you are looking for. Your background would be the rounded rectangle with gradient shading. The background colors can be defined as explained here. Your seek bar can be built using a LayerList. The layer list can be defined in XML and modified in code. You can also forgo the layer list and draw that seek bar programmatically or fit everything into one drawable. Which you do will depends on your design constraints.
The thumb can easily be a custom thumb.
You will likely wind up with mostly XML but some code but not much. I would consider placing the code in a custom view that extends from a standard SeekBar.
You can edit the following resources.
https://github.com/divyanshub024/ColorSeekBar
custom scroll able multi color seek bar
I built something similar with Jetpack Compose, instead of using different colors with intervals it creates gradients from colors, but what you ask is a little work on current build and it can display anything as thumb. You can check source code and implement drawing over track section. If it's much work i can add similar features when i'm available.
The easiest way of doing this in Compose Canvas, for View it's a custom View that draws inside onDraw.
You basically draw a line with width and rounded cap or a rounded rectangle and draw border with a stroke around it. Do some interpolation for changing from your value range to pixels on screen and get the current value based on users touch position and interpolate it to range defined.
Let's say your Slider is 1000px wide. And your range is between 0f and 1f, you translate touch on 600px to 0.6 value and vice versa. For different colors you can pass a List<Pair<Color,Float> to divide slider between color based on float based stops.
For drawing lines you set 3 types of heights and use modulus to assign each height in every 1, 5 and 20 value. I have something similar for building Compass with View here
https://github.com/SmartToolFactory/Compose-Colorful-Sliders

How do I let the user move a circle into another circles by dragging it in Android?

At the start I want the user to see:
The then want to give the user the choice to be able to drag H or C into the circle, so that it looks like:
This means while the user drags the H into the circles the other items that are already in the circle are have to move to make space for it. Ideally I would want them to be evenly distributed in the bigger circle. To have a nice UX I want the transition between the two images to be visible.
How do I best implement this UI?
the best way to do this is you use separate overlapping imageview to construct the big image and use separate imageview for each part image. then use imageview.setOnDragListener() for drag image and imgview.setOnTouchListener() to create shadow. study about this and you will definitely do it.

Android - custom view and animation

I am experimenting with Views in Android and am trying to create a custom 'widget'. What I want to do is create a portion of a circle with an indicator at 12'o clock. I'd then like to to swipe over the circle and when I do, I'd like to see the indicator move to left or right corresponding to a swipe to the left or the right.
I have looked up a number of sources however I am unsure of how to draw an 'indicator' within the arc. In addtion, what needs to be done to animate the arc ? Can this be achieved without OpenGL ?
I am aware of the circlular progress bar and I believe the problem is quite similar, however I didn't have to add a marker inside the circle.
Here is an image of the screen shot of the View I would like to recreate:
This approach would work,Creating a View with rounded corners and position it to bottom to make it seem like arc

What options are there for arranging custom ImageViews

I have recently completed a simple drag and drop shapes game. It had the user drag a shape (ImageView) to another "empty place holder" ImageView.
I now want to make this a little more advanced, instead of dragging a simple shape, I want to make a puzzle of various non-orthogonal shapes, for example breaking a circle into 5 different pieces. What I'm having a problem with right now is how to design the layout. I do not know how to make a truly "custom" shaped ImageView, as far as I can find from my research it's not possible. So my idea for now is to overlap a number of square ImageViews, each of which will have only a subset of an image and the rest transparent. Thus the final output will look like it's a number of custom shaped ImageViews.
Example:
+ + +
Because only the internal sections are "visible" and the rest of the circle is transparent, when all of these pieces are placed in the same spot on the screen, the final image will look like:
I haven't tried this yet... but I foresee at least one problem. When I go to drag the pieces over to this puzzle, they will all "snap" into place when dragged to the same place. Because in reality all I really have here is a picture of a circle inside a ImageView which has some invisible rectangular boundary around it.
Hopefully this situation is clear. Now my questions:
Is it possible to have truly custom shaped ImageViews instead of my idea of overlapping images?
If what I'm thinking is the best way to handle this puzzle idea, then what property can be changed such that the "drop" action does not happen at the same place for all of these puzzle pieces? If I wanted to "drop" the pizza shaped piece, I'd like it to only snap into place when it go close to the top left of the circle.
Note: I am new to Android programming, and somewhat new to Java/XML as well, it’s very likely I’m overlooking something, so please feel free to suggest other approaches as you see fit.
Not really. Overlapping views is generally the way it's done. You could also use one View and override the drawing action yourself (multiple bitmaps drawn at relative locations within the View), but that would make the drag-drop aspect significantly harder.
If the Views are all the same size, with the visible portions in the correct relative placement in each, they should snap together correctly. This is because the snap is (I believe) based on the position of the upper-left corner of the View. If the pizza-shaped piece's visible portion is correct with regards to that, it should snap in at exactly the right spot.
So you have certain places you want to accept the drops, and I'm assuming you know their coordinates, say (d_x,d_y).
Then why not simply monitor the coordinate of the center (p_x,p_y) of image view of the piece you are dragging, say the "pizza" piece, and when the distance between the the piece and drop point is within an acceptable amount accept the drop.
But if you are asking if there is some way to make non-rectangular image views I don't believe that is possible.
However I don't think it is necessary in your case, because I believe even if you want them to drag the piece precisely into place you can calculate the coordinates where the draggable rectangle needs to go with knowledge of the shape of the piece and the assumption that the rectangle wraps the piece.

How to animate views?

I'm working on a game that in some ways is similar to Tetris (imagine a 2D array of colored squares that sometimes move around)
I am trying to animate the individual squares so they will smoothly slide down from coordinate to the next. Since I wanted to use Android's built-in tweening feature, the animation has to apply to the whole View (rather than parts of it). This doesn't work well for me because I only want some of the colored squares to slide down, and the rest of them to stay still.
The (theoretical) solution I came up with to resolve this is to make 2 Views, layered directly on top of each other. The top view is for animating squares when they need to move, and the bottom layer is for the static squares. The animation-layer is transparent until I am ready to animate something. I then simply turn on the colored square in the animation-layer, tween it to the new location, and turn it back off when done. In the same time span, the static-layer just turns squares on and off at the right time to make the whole thing look seamless to the end user.
The proposed solution is just a theory, since I haven't been able to make it work correctly yet. Since I have been having trouble, I was wondering if this is even the best way to solve the problem? Perhaps there is a more elegant solution that I am over looking? Anyone know of a better way?
If you just want to animate a single element check out the namespace android.view.animation.Animation. You can also use Drawable shapes and draw them directly. Finally, if you want a simulation then you will have to look into threading. Basically you will create a timer to update the canvas for you based on an interval. There are some other view canvases you can use as well like the GLView canvas.

Categories

Resources