java - listItem 的缩放动画

标签 java android focus android-animation onitemselectedlistener

我有一个 ListView。我知道如何突出显示或更改 ListView 中所选项目的背景。 但是我想像这样缩放所选项目:

(选中的项目比这张图片中的其他列表项大一点)

enter image description here

有人可以帮我做吗?

最佳答案

我找到了解决方案,我为列表项设置了 OnFocusChangeListener 并为它们设置了动画:

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();
    }
};

放大.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" />

减少.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" />

关于java - listItem 的缩放动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26571944/

相关文章:

google-chrome - 当浏览器未处于焦点时,jVectorMap onRegionClick 在 Chrome 中第一次单击时不会触发

javascript - 如何使用javascript在文本框上触发焦点事件?

java - JLabel 位置在 Java 中不起作用

JavaCV 示例/教程

android - 当我在 View.VISIBLE 之后调用 View.GONE 时 ProgressBar 不显示(但仅在旧手机上)

android - 在CircleCI中构建android应用程序测试时找不到gradlew

java - 在 JSP 中使用 Struts2 的 session

java - 从另一个数组定义数组

android - Activity 生命周期 X 电源按钮 X 锁屏

datagridview - 在 ComboBox 中更改选择时,在 DataGridView 中提交更改