Android - ObjectAnimator sets rotation value

I want the relative layout to expand and the bottom of the review to be fixed.
I have a relative layout -

private RelativeLayout rlOutdoorSection; 

Initialized it -

 rlOutdoorSection = (RelativeLayout) findViewById(R.id.rlOutdoorSection); 

Created by ObjectAnimator -

 scaleUpOutdoor = ObjectAnimator.ofFloat(rlOutdoorSection, "scaleY", 1f, 2.6f); scaleUpOutdoor.setDuration(3000); 

start the animation -

 scaleDownOutdoor.start(); 

Currently, a view is becoming scaled using rotation values ​​in the center of the view.

How can I make sure the view scales with a fixed bottom?

Thanks at Advance.

+4
source share
1 answer

First we need to compute HEIGHT representations -

 iOutdoorCompressedHeight = rlOutdoorSection.getMeasuredHeight(); 

Use this HEIGHT as the axis around which you want to scale the view.

 rlOutdoorSection.setPivotX(0f); rlOutdoorSection.setPivotY(iOutdoorCompressedHeight); 

The trick here may be with a measured viewing height.
In Activity calculate height in

 @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); // Here calculate the height / width } 

In a FRAGMENT use the global layout receiver -

 rlOutdoorSection = (RelativeLayout) vMain .findViewById(R.id.rlOutdoorSection); ViewTreeObserver vtoOutdoor = rlIndoorSection.getViewTreeObserver(); vtoOutdoor.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { iOutdoorCompressedHeight = rlOutdoorSection.getMeasuredHeight(); rlOutdoorSection.setPivotX(0f); rlOutdoorSection.setPivotY(iOutdoorCompressedHeight); } }); 

Hope this helps someone.

+8
source

Source: https://habr.com/ru/post/1496083/


All Articles