I want to create a custom view which should have animation. I want to draw the circle with specifying the radius and some drawable element in this custom view which should be moving in this circle.
I know how to draw a circle, how to add a drawable element, but I don`t know how to animate this drawable element.
Should I write animation methods in custom view or better to create another class with animation logics and apply it to my custom view. Can you give me some advice?
I think that second case is wrong because in this way a whole view will be animating, but not only drawable.
Related
I'm new to Android and need advice. I have a GridLayout with multiple ImageViews. Each ImageView has a drawable and a background color. On button click, I want to animate two things, depending on user's input: 1) move the entire view to a new position (this part is clear and doesn't cause problems), and 2) move only the image's drawable to a new cell, leaving the view with the background color at the original position. I'm completely stuck on this second task. How do I move drawables using animation? Thanks for any help.
move only the image's drawable to a new cell, leaving the view with the background color at the original position
I think you can't "move a drawable". But you can do the following:
introduce a View - let's call it movingDrawableView - showing just the drawable but with a transparent background, this View is hidden at first
Set the position of this movingDrawableView to overlap the View with the drawable and the colored background and make it visible
Set the drawable of the View with the colored background to null
start the animation for movingDrawableView
as soon as the animation is finished, fill the underlying View with the drawable and show a background as required
hide movingDrawableView
create a ripple.xml
set the drawable to a ImageView
I found that the circle is draw outside current ImageView
How does this work
The reason is about hardware accelerate,see the function isProjected() in RippleDrawable.
If isProjected() return true, DislayList will hold this RenderNode
(see http://androidxref.com/7.1.1_r6/xref/frameworks/base/libs/hwui/DisplayListCanvas.cpp#addRenderNodeOp)
Easiest way- put the ImageView inside a larger layout, and apply the ripple to the layout.
I have a custom view like a circle's quadrant. I wish to fill color in the view sequentially starting from left. How do I go about coding this animation?
I have a transparent layout in android, and behind the layout there is an image. how to make the linear blur ? I found examples to make the image itself blur but I don't want to make whole image blue, just only the part that is behind the linear layout.
Set a semitransparent Blur image to the linear layout or simplest set a color to linear layout and set it to semitransparent by defining alpha
edited solution
do this...
1.) create a blur copy of the image u have on background.
2.) clip the image by using
Bitmap croppedBmp = Bitmap.createBitmap(originalBmp, startX, startY, widthLayout , heightOfLayout);
3.) set this image in the Linear Layout using an image-view with height and width attribute as fill-parent.
I have pretty complex solution, so there won't be any code. So, here is idea, step by step:
Let's assume that your layout have just single custom LinearLayout. No ImageView as a background.
What we going to do, is draw background drawable of LinearLayout by our own, so it will first draw full image and then draw blurred square from the same image on top. Content of LinearLayout might be moved to desired position using paddings.
So, create something like MyLinearLayout and put it to your layout resource. Provide required constructors.
Override onAttachedToWindow() and onDetachedFromWindow() methods. Inside them we should load our background Bitmap and recycle it accordingly. Let's name it mBackground
Override draw() method. Inside it we're going to first draw our mBackground.
Then, you can use Canvas#clipRect() method to crop drawing area of Canvas to some specified rectangle. In your case, this rectangle should be the area below your content. You can figure it out using View#getPadding*() methods. Don't forget to call canvas#save() before clipping drawing area.
Now you can draw your bitmap once again with blur (I don't know which method exactly you're using, so let's assume that you know how to do it... but you still can share it with us :) ). Cool thing is that you can just draw the same Bitmap once again in full scale - since we had called clipRect before, it will be drawn only within this area. Don't forget to call canvas#restore() after drawing background.
Call super.draw() to draw rest of the stuff, that your LinearLayout contains.
I'm trying to make a circle of one color on a background of another.
background = new ShapeDrawable(new OvalShape());
background.getPaint().setColor(main.getResources().getColor(R.color.XXX));
view.SetBackground(background);
will work for the colored circle, and
view.setBackgroundColor(getResources().getColor(R.color.XXX));
will work for the background, but they're mutually exclusive. It just ends up with what I did last. Is there a way to make the circle on another overlapping view or something like that?
setBackgroundColor() is basically a short cut for changing the view's background to a colour drawable.
To do what you want you could try one of the 2 things described below:
Put a view in a FrameLayout, set the background colour in the FrameLayout, and put the shape in the view.
You could also try to use ImageView, which can have a background and another drawable with setImageDrawable() method.