Set animation YDelta in Java class?

430 views Asked by At

I am running an animation within my listview, and I wondering how I am able to set the xml attribute, yDelta, within my java class. It is contingent upon the size of the current row, so I can't use a single value. Here is my animation code

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
    android:fromYDelta="20%p"
    android:toYDelta="20"
    android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="1.0"
    android:duration="@android:integer/config_mediumAnimTime" />

here is my java code

public void updateDataList(ArrayList<HashMap<String, String>> newList){
    final ArrayList<HashMap<String, String>> newListAdd = newList;

        Animation anim = AnimationUtils.loadAnimation(
                liveStreamFragment.getActivity(), R.anim.top_to_down
        );

        anim.setDuration(2000);
        list.startAnimation(anim);

        new Handler().postDelayed(new Runnable() {

            public void run() {

                oslist.clear();
                oslist.addAll(newListAdd);
                LiveAdapter.this.notifyDataSetChanged();

            }

        }, anim.getDuration());

}
1

There are 1 answers

1
Anton Kovalyov On

Accordingly to this documentation you can set it in constructor:

TranslateAnimation translate = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta);

Also check this similar question.