How to set “toYDelta” attribute in java code?

2019-07-19 16:15发布

问题:

I've got many textViews and below each of them, a tableLayout which has visibility.GONE at the very beginning . I am trying to expand the tableLayout which is belong to a textView when the textView is clicked . I've assigned alpha animation to tableLayouts and translate animation to those textViews are below the clicked one .

since the size of my tableLayout are different I have to set toYDelta and fromYDelta separately in a new animation for clicking every textView !! and I think it is totally hard code !!!

My question is : Is there any method I can use it to modify toYDelta in may code programmatically ?

Or can anyone help me other way to do that please ?

回答1:

There are several alternatives for doing this. The simplest one is probably to use a ViewPropertyAnimator, e.g.

view.animate().translationY(value);

To get the current value (for example if you want to update it with a fixed offset) you can use view.getTranslationY().

See http://developer.android.com/guide/topics/graphics/prop-animation.html