Is there any way to set rotation to the layout parameter - android

I want to set rotation to the view through Layout Parameter by calling setLayoutParams
Here I can set margins
RelativeLayout.LayoutParams paramsForSpinnerTextView=(RelativeLayout.LayoutParams)spinnerTextView.getLayoutParams();
paramsForSpinnerTextView.setMargins(30,30,30,30);
spinnerTextView.setLayoutParams(paramsForSpinnerTextView);
Same way, Is there any way to set rotation to the layout parameter.
EDIT:
Yes, I can simply rotate the view using spinnerTextView.setRotation(-90) but this is instantaneous and does not show any animation. My parent layout is Relativelayout with a attribute android:animateLayoutChanges="true" until unless I change the child views attribute using setlayoutParams animation attribute of parent will not do anything.
And I also know that I can use rotate animation but that will not move the touch area of the view.

As per I know there is no way to set rotation to the layout parameter. There are other ways to achieve what you want.
Apply rotation animation
Listen to the animation end event
There, just call setRotation(required_angle) on your view

Related

How to set translation or margin to child and avoid parent's paddings

I need to move some layout to the area of parents paddings but the view just cutted. I was trying to set - margin for child and transition but nothing works good.
Can anybody help me with that? I'm using ConstraintLayout as a parent and for some reason I don't want to change it's paddings.
Set the following on the parent:
android:clipToPadding="false"
This will allow the child to draw inside the parent's padding.

Change the opacity/transparency of a view and affect the child views too

I have a relative layout with child TextViews.
The background of the parent RelativeLayout is white and I was wondering how I could change the alpha to change the opacity of the whole view programmatically (including children).
I am trying:
getBackground().setAlpha(0.4);
But that expects an int and not a float.
If I do:
getBackground().setAlpha((int)(0.4 * 255));
The latter changes the view but makes it darker than I want. Also the children do not seem to change. It seems to affect only the background while I want something that makes everything more "grayed" out/less transparent.
What am I doing wrong?
Have you tried using android:background="#88000000" in layout file. You can change alpha and color values as required.
That's because you are changing the backgound of the layout and not the layout itself. So instead of myRelativeLayout.getBackground().setAlpha(), use this: myRelativeLayout.setAlpha(0.4f).

Is android:animateLayoutChanges supposed to work when a child view's height is updated?

http://developer.android.com/training/animation/layout.html
<LinearLayout
animateLayoutChanges="true">
<View1/>
<View2/>
<View3/>
</LinearLayout>
Let's say View2's height increases at runtime. I would expect View3 to animate downward. Instead, it snaps directly into its new position.
Why does my desired animation not occur?
According to https://developer.android.com/reference/android/animation/LayoutTransition.html
By default, all transition types except CHANGING are enabled.
So if you want to animate when a child changes its size. You can do so by
LayoutTransition layoutTransition = new LayoutTransition();
layoutTransition.enableTransitionType(LayoutTransition.CHANGING);
parentView.setLayoutTransition(layoutTransition);

Animate view regardless of its layout-container

I'm trying to apply a TranslateAnimation to an ImageView inside of a LinearLayout. As soon as the ImageView(marked "1" in the image below) crosses the bounds of the LinearLayout that contains the ImageView, it goes "black"/disappears. This does NOT happen if I animate the entire green LinearLayout, so I don't think it has to do with it's z-value. Rather, I believe that the ImageView can't visually "escape" its container layout (green). What can I do to make the ImageView display in front of everything when the animation is being performed? I've already tried .bringToFront()(followed by .requestLayout/.invalidate of the root view).
Try to set android:clipChildren="false" in a parent container

Set attributes (margin, gravity, etc...) to an Android view programmatically (without XML)

I need to create a GUI (layout+views) in my .java activity class (I know it's far more flexible and easier to use .xml layout file, but I don't want to use it for now).
I can't find any setGravity() (but a "Gravity" object I can't figure how to use) or any set setMargin() method for the "View" object.
What is the easiest way to do it ?
Thanx.
For setting the margin on component. The following leaves the existing margins as previously set and sets the left margin as zero.
TextView title = ((TextView)findViewById(R.id.default_panel_title))
final ViewGroup.MarginLayoutParams lpt =(MarginLayoutParams)title.getLayoutParams();
lpt.setMargins(0,lpt.topMargin,lpt.rightMargin,lpt.bottomMargin);
title.setLayoutParams(lpt);
You can add gravity to the "layouts" not to the "controls". Try to set gravity to any of your Linear/Relative or Frame layouts using setGravity(); .
Eg:
LinearLayout lll = (LinearLayout) findViewById(R.id.layoutname);
lll.setGravity(Gravity.CENTER);

Categories

Resources