我有ListView
。我知道如何突出显示或更改ListView中所选项目的背景。
但我想按比例缩放所选项目:
(所选项目比此图片中的其他列表项目稍大)
任何人都可以帮我这么做吗?
答案 0 :(得分:1)
我找到了解决方案,我为列表项设置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();
}
};
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" />