我有一个动画列表项目的列表视图,当列表视图中的项目被选中时,它会淡出并变得不可见,但我遇到的问题是,当选择了另一个项目时它不会恢复到正常状态
我已设置android:fillEnabled="true"
和android:fillAfter="true"
以使列表项保持动画。
像这样:
这是animation.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/bounce_interpolator"
android:fillEnabled="true"
android:fillAfter="true"
>
<scale
android:duration="600"
android:fromXScale="0.75"
android:fromYScale="0.75"
android:pivotX="25%"
android:pivotY="25%"
android:toXScale="1.00"
android:toYScale="1.00" />
<alpha
android:duration="250"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>
列表视图:
@Override
public void onComplete(List<Profile> friends) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mSpinner.setVisibility(View.GONE);
mSpinner.clearAnimation();
}
});
// populate list
List<String> values = new ArrayList<String>();
for (Profile profile : friends) {
//profile.getInstalled();
values.add(profile.getName());
}
listView = (ListView) findViewById(R.id.list);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> av, final View view, final int i, long i2) {
Animation anim = AnimationUtils.loadAnimation(SendActivity.this, R.anim.jump);
view.startAnimation(anim);
}
});
ArrayAdapter<String> friendsListAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_items2, values);
friendsListAdapter.sort(new Comparator<String>() {
@Override
public int compare(String lhs, String rhs) {
return lhs.compareTo(rhs);
}
});
mFriendsList.setAdapter(friendsListAdapter);
}
};
关于我如何做到这一点的任何提示?
答案 0 :(得分:1)
还有其他(更优雅)的方法。但这首先是我的想法+我已经在评论中提出了这个解决方案
private View animatedView = null;
//....code .. code .. code...
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> av, final View view, final int i, long i2) {
if (animatedView != null){
Animation anim = AnimationUtils.loadAnimation(SendActivity.this, R.anim.unjump);
animatedView.startAnimation(anim);
}
Animation anim = AnimationUtils.loadAnimation(SendActivity.this, R.anim.jump);
view.startAnimation(anim);
animatedView = view;
}
});
//another animation (called it unjump) to clear the alpha level
//reusing your stuff
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/bounce_interpolator"
android:fillEnabled="true"
android:fillAfter="true"
>
<scale
android:duration="600"
android:fromXScale="0.75"
android:fromYScale="0.75"
android:pivotX="25%"
android:pivotY="25%"
android:toXScale="1.00"
android:toYScale="1.00" />
<alpha
android:duration="250"
android:fromAlpha="0.0" //exchanged from/to -alpha levels (so this would come from transparent to non-transparent)
android:toAlpha="1.0" />
</set>
答案 1 :(得分:0)
您需要在适配器的getView
方法中设计一些逻辑,以便所选行的后备Object具有布尔属性,类似于isClicked。在getView
方法中检查对象是否为true,如果是,则返回null,否则返回视图。
您可以类似地设计备用逻辑。