简体   繁体   中英

Scale Animation for listItem

I have a ListView . I know how to highlight or change the background of a selected item in a ListView. But I want to scale the selected item like this:

(selected item is a little bigger than other list items in this picture)

在此输入图像描述

Can anyone help me to do that?

I found the solution, I set OnFocusChangeListener for List items and set animation for them:

OnFocusChangeListener itemFocusChangeListener = new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
                int focus = 0;
        if (hasFocus) {
            focus = R.anim.enlarge;
        } else {
            focus = R.anim.decrease;
        }
        Animation mAnimation = AnimationUtils.loadAnimation(
                getActivity().getApplication(), focus);
        mAnimation.setBackgroundColor(Color.TRANSPARENT);
        mAnimation.setFillAfter(hasFocus);
        v.startAnimation(mAnimation);
        mAnimation.start();
        v.bringToFront();
    }
};

enlarg.xml:

<?xml version="1.0" encoding= "UTF-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
<scale
    android:duration="100"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:pivotX="50.0%"
    android:pivotY="50.0%"
    android:repeatCount="0"
    android:toXScale="1.15"
    android:toYScale="1.15" />

decrease.xml:

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="false"
android:fillBefore="true"
android:shareInterpolator="false" >

<scale
    android:duration="100"
    android:fromXScale="1.1"
    android:fromYScale="1.1"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:pivotX="50.0%"
    android:pivotY="50.0%"
    android:repeatCount="0"
    android:toXScale="1.0"
    android:toYScale="1.0" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM