I wanted to animate view as shown in the image. How to do it?
Click here to see the image
I have the following code but how to set the parameter current?
How Animation works?
When the user moves his finger over the list of icons, the height of the current icon, where the user has touched, is set to 400.
TransitionManager.beginDelayedTransition(layout);
View child = layout.getChildAt(current);
child.setMinimumHeight(400);
where current is of type int.
Shouldn't try to change a View height, margin or padding if you want to do an animation.
Do a scale animation instead on focus:
View child = layout.getChildAt(current);
child.animate().scaleX(2f).scaleY(2f).setDuration(400).start();
Scale to normal size on unfocus:
View child = layout.getChildAt(current);
child.animate().scaleX(1f).scaleY(1f).setDuration(400).start();
Related
I have 2 views.
The view A is in wrap_content and with a max_width of 100dp. Then there's this view B next to him. I want view B to move below view A when view A reachs 100 dp width.
How can I accomplish this with Constraint Layout and xml? Or must be done programatically?
You can move change a view's constraint's programmatically. You could listen for the view's width and perform a change when it reaches >100dp.
Video on the subject:
https://www.youtube.com/watch?v=-sPOtGqd5OA
The pattern of the layout is below:
---LinearLayout vertical
---LinearLayout -> contains a LinearLayout that shapes like rectangle(setVisibility-> Gone)
---RecyclerView -> below the above layout of rectangle
Originally, I set a slide-down animation of RecyclerView from the top of the window to a position where it gives enough space for the rectangle to show and when the animation ends the LinearLayout of rectangle is shown by invoking the method setVisibility(Visible)
Problem: when I set the rectangle visible, it is visible as expected but recycler view is dropped down the space as much as the rectangle's height, leaving blank space between the rectangle and the RecyclerView. I wonder what might cause this and how to fix this? Thanks!
I think you may not change the position of the RecyclerView and only set the visibility of the LinearLayout to visible. Changing the visibility will redraw the whole layout and the layout that was Gone will take its needed height, so the space between the top of the recycler view and the bottom of the layout will be (animation height + layout height) and that is why there is an empty space
I want to create transparent system overlay window, which has several round views:
Green view is VISIBLE, red one is INVISIBLE. The thing is that I need red view to pass touches to the underlying window, but by default it doesn't.
I tried setting visibility of red view to GONE, but then overall size of containing view changes. Since I need the containing view to be snapped to the right edge of the screen, this means that position of green view changes, and I don't want this.
Is there any way to override default touch handling in INVISIBLE state?
Here's an actual screenshot to make my question more clear:
Also, I had to override dispatchTouchEvent() to dispatch touch events correctly:
#Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Circle target=null;
int targetIndex=-1;
for (int i=0; i<getChildCount(); i++) {
Circle child=(Circle) getChildAt(i);
if (child.viewMetrics.containsPoint(ev.getX(), ev.getY()) && (ev.getAction()==MotionEvent.ACTION_MOVE || child.isVisible())) {
target=child;
targetIndex=i;
break;
}
}
onMotionEvent(ev, target, targetIndex);
Log.d(">| CircularLayout", "action: "+ev.getAction()+", target: "+target);
return target!=null && target.dispatchTouchEvent(ev);
}
Create custom view to do this. In such case you do not need any trickery related to visible invisible - it's you who decide what is your clickable area and also you who decies what area will alter the state (like is drawn as pressed on touch event). So your custom view should be of the size of desired area but in your onDraw() you shall only draw the change on that smaller inner area.
Here are basics on how to create custom views: http://developer.android.com/training/custom-views/index.html
What I ended up doing is calculating two sets of view dimensions: maximum possible (size of the red area) and current (green area). When child view is hidden or shown I set width and height of window LayoutParams to current dimensions and then set difference between maximum and current dimensions to y and x parameters of LayoutParams.
For some reason applying modified LayoutParams triggers measure/layout pass twice (which in turn causes the view to "bounce"), but that seems to be the whole new story.
suppose i have two image view v1,v2.
imageview v1,v2;
v1=(Imageview)findviewbyId(R.id.view1);
v2=(Imageview)findviewbyId(R.id.view2);
How do I check that v1 ontop of v2 or not.
You can set onclick listener for both of it so that when the user clicks so that the top of the imageview only gets clicked. By this u can get which imageview is up top.
you may check by getting co-ordinates of the image by using this link
and can check which image is top and which is bottom with that co-ordinates
one suggestiton: get their location and height
minus them and configure if on top of
You can calculate it with the position and the width and height of the View.
Position: Use View.getLocationOnScreen() and/or getLocationInWindow().
Width/height: Use View.getWidth() and View.getHeight().
The view that is defined first in your xml layout will be drawn first. The next view will be drawn on top of the previous view if there is any.
By that principle, you can ask your frame/relative layout to check the ordering where the child views are ordered:
int indexV1 = layout.indexOfChild(v1);
int indexV2 = layout.indexOfChild(v2);
if(indexV1 < indexV2) {
// v1 is below v2
}
If I try to set the top/left margins of the child of a RelativeLayout view so that the child view would appear partially off the right/bottom of the screen, the problem is that the view is shrunk in size and appears fully on the screen (which satisfies the top/left margins, but changes the size). I don't want the size to change.
I programmatically set the position of a child view of a RelativeLayout view by setting the top and left margins, something like this:
RelativeLayout.LayoutParams childViewParams = new RelativeLayout.LayoutParams(250,250);
childView = new ImageView(this);
relLayoutView.addView(childView);
childViewParams.leftMargin = somethingBigEnoughToPutOffRightHandSide;
childViewParams.topMargin = something;
childView.setLayoutParams(childViewParams);
If I set the top/left margins such that this child view should appear partly off left/top part of the screen, everything works as expected, no change in size, and the view moves partially off screen.
How can I specify the position of the view so that the size of the view is never changed, no matter the position, partially or fully off screen?
All that is needed is to also set the right and bottom margins to negative values exceeding the possible size of the view and the screen. Something like this:
RelativeLayout.MarginLayoutParams params = (RelativeLayout.MarginLayoutParams) someView.getLayoutParams();
params.setMargins(leftMargin,rightMargin,-1000,-1000);
someView.setLayoutParams(params);