How to disable effect when addView in Android - android

I have a problem : When I add a CustomView into FrameLayout with some params to set CustomView position at bottom of FrameLayout. The first, CustomView is created with some params, and I used addView() function to add it to FrameLayout. But first CustomView is displayed at top of FrameLayout, and after that It moving(very fast) to bottom of FrameLayout.
How to disable this effect?

You need to disable the LayoutTransition for your view.
LayoutTransition layoutTransition = yourFrameLayout.getLayoutTransition();
layoutTransition.disableTransitionType(LayoutTransition.APPEARING);
Read more about LayoutTransition on the android developers website.

Related

Android FlexboxLayout : android:animateLayoutChanges not working when child view resized

I added this option to my FlexboxLayout for had animation when children move :
android:animateLayoutChanges="true"
Unfortunately child view are animated only when I add child, but not when one child is resized!
Have you got any idea to always have an animation?
To animate children when they change their size you need to enable CHANGING transition type of the container's layoutTransition:
LayoutTransition layoutTransition = new LayoutTransition();
layoutTransition.enableTransitionType(LayoutTransition.CHANGING);
parentView.setLayoutTransition(layoutTransition);
LayoutTransition

Android - LayoutTransition hides views inside the animated view before closing it

I have a LinearLayout that contains several views - when I add or remove it from my view I used the default LayoutTransition.
I'm adding the view to my AppbarLayout - and I added the animations programmatically by setting a new LayoutAnimation on the appbar before adding the view and setting it to null after the view is added - I don't do it using the tag in the xml due to https://code.google.com/p/android/issues/detail?id=191170
The problem is that when i remove it from the view the default animation is done in two parts
all the views inside immediately disappear
the closing of the view is animated from bottom to top
Which change is needed to the LayoutTransition in order to have only the 2nd animation where the view is closed from bottom to top?
CommonsWare answer
Modify its LayoutParams to move it to the end position. Use
getLayoutParams() on the View, cast it to the appropriate type based
on its container, modify the LayoutParams object, then call
setLayoutParams() on the View to commit the changes.
Try this:
final LinearLayout container = (LinearLayout) findViewById(R.id.container);
LayoutTransition transition = container.getLayoutTransition();
transition.disableTransitionType(LayoutTransition.APPEARING);
transition.disableTransitionType(LayoutTransition.DISAPPEARING);

edit layout of existing child in RelativeLayout

I have a RelativeLayout with a number of children. The RelativeLayout is the main layout of my activity. I need to add to one of the children the layout value layout_alignParentBottom="true". I need to do this programmatically. the link How to set the android property layout_alignParentBottom to a button dynamically is not working for me because, basically, I don't want to have to inflate the RelativeLayout as I already have it at the setContentView(...). Any ideas how to do this?
I figured it out:
RelativeLayout.LayoutParams layout = (LayoutParams) theChild.getLayoutParams();
layout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

Android - Aligning a view (button) within another View in code?

I have a custom view which will be jar'ed up and added into another project. In the view I want to give an option of a button.
Here is what I have in the CustomView class.
final CustomView currentView = (CustomView) findViewById(this.getId());
RelativeLayout.LayoutParams params = (new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT ));
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
closeButton.setLayoutParams(params);
currentView.addView(closeButton);
This is all wrapped in a RelativeLayout Tag as well as the other objects of the application
Everything compiles however in the CustomView the Button is aligning left instead of right.Any Ideas???
I would guess the problem is your CustomView. It probably doesn't take the entire width of the window, and is just wide enough to fill its children (which, in your case, is the close button). Make sure your CustomView has a fill_parent horizontal layout.
Since your CustomView extends WebView, which, in turn, extends AbsoluteLayout, you can't expect it to handle RelativeLayout's parameters. Instead, it's best you put your customview and your close button inside a RelativeLayout and position them properly.
When adding your closeButton to your currentView you need to supply the LayoutParams as an argument as well in order for them to take effect.
Basically, switch
currentView.addView(closeButton);
with
currentView.addView(closeButton, params);
Since the width of your button is set to wrap_content, you could also try setting its layout_gravity to right.
params.gravity = Gravity.RIGHT;

I have created Progressbar programmatically, now how can i keep it center of screen and ontop of other views when made visible inside linearlayout?

I have created Progressbar programmatically, now how can i keep it at the center of screen and ontop of other views when made visible inside linearlayout ?
Consider using a RelativeLayout instead of the LinearLayout and add attributes to your ProgressBar: centerInParent = true.
Covering up views under another view can only be done in RelativeLayout (or FrameLayout, but more tricky)

Categories

Resources