在Android的ListView项翻转动画 [英] Flip Animation in Android Listview item
本文介绍了在Android的ListView项翻转动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示前我的每个列表视图
项目和背面与翻转动画
。动画效果很好,但动画的结果应用到其他项目也。进而,当我上下滚动了我的项目的位置变化。我的code是如下:
公开查看getView(最终诠释的位置,最后查看convertView,ViewGroup中父){
ArtItemHolder持有人;
查看查看= convertView;
如果(查看== NULL){
LayoutInflater充气=((活动)this.context).getLayoutInflater();
持有人=新ArtItemHolder();
鉴于= inflater.inflate(R.layout.feed_list_item,父母,假);
holder.image =(ImageView的)view.findViewById(R.id.img_Image);
holder.pubDate =(TextView中)view.findViewById(R.id.txt_puslishDate);
holder.arTitle =(TextView中)view.findViewById(R.id.txt_arTitle);
holder.commentCount =(TextView中)view.findViewById(R.id.txt_commentCount);
holder.rotator =(ImageView的)view.findViewById(R.id.card_roretor);
holder.cardFace = view.findViewById(R.id.card_face); //首先feed_list_item.xml 2儿童的家长布局
holder.cardBack = view.findViewById(R.id.card_back); //第二feed_list_item.xml 2儿童的家长布局
view.setTag(保持器);
} 其他 {
支架=(AdvItemHolder)view.getTag();
}
holder.rotator.setOnClickListener(新MyFlipperListener(视图,holder.cardFace,holder.cardBack));
返回查看;
}
私有类MyFlipperListener实现OnClickListener {
查看父,frontFace,背面;
公共MyFlipperListener(查看父,查看frontFace,查看背面){
this.parent =父母;
this.frontFace = frontFace;
this.backFace =背面;
}
公共无效的onClick(视图v){
FlipAnimation flipAnimation =新FlipAnimation(frontFace,背面);
如果(frontFace.getVisibility()== View.GONE)
{
flipAnimation.reverse();
}
parent.startAnimation(flipAnimation);
}
}
私有静态类ArtItemHolder {
ImageView的形象;
TextView的pubdate的;
TextView的arTitle;
TextView的commentCount;
ImageView的转子;
查看cardFace,cardBack;
}
我的布局XML在列表视图项
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
机器人:重力=中心>
<的LinearLayout
机器人:ID =@ + ID / card_face
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:背景=@可绘制/ feed_item_selector
机器人:layout_margin =8DIP
机器人:填充=2DIP>
##########主要内容HERE ###########
< / LinearLayout中>
<的LinearLayout
机器人:ID =@ + ID / card_back
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:背景=@可绘制/ feed_item_selector
机器人:layout_margin =8DIP
机器人:填充=2DIP
机器人:能见度=水涨船高>
##########一些信息关于主要内容HERE ###########
< / LinearLayout中>
< / LinearLayout中>
更新
FlipAnimation flipAnimation =新FlipAnimation(holder.cardFace,holder.cardBack);
holder.rotator.setOnClickListener(新MyFlipperListener(视图,holder.cardFace,flipAnimation));
私有类MyFlipperListener实现OnClickListener {
查看父,frontFace;
FlipAnimation flipAnimation;
公共MyFlipperListener(查看父,查看frontFace,FlipAnimation翻转){
this.parent =父母;
this.frontFace = frontFace;
this.flipAnimation =翻转;
}
公共无效的onClick(视图v){
如果(frontFace.getVisibility()== View.GONE){
flipAnimation.reverse();
}
parent.startAnimation(flipAnimation);
}
}
解决方案
AYT检查我的解决方案...
公开查看getView(最终诠释的位置,最后查看convertView,ViewGroup中父){
ArtItemHolder持有人;
查看查看= convertView;
如果(查看== NULL){
LayoutInflater充气=((活动)上下文).getLayoutInflater();
持有人=新ArtItemHolder();
鉴于= inflater.inflate(R.layout.feed_list_item,父母,假);
holder.image =(ImageView的)view.findViewById(R.id.img_Image);
holder.pubDate =(TextView中)view.findViewById(R.id.txt_puslishDate);
holder.arTitle =(TextView中)view.findViewById(R.id.txt_arTitle);
holder.commentCount =(TextView中)view.findViewById(R.id.txt_commentCount);
holder.rotator =(ImageView的)view.findViewById(R.id.card_roretor);
holder.rotator.setTag(假); //把布尔这里..
holder.cardFace = view.findViewById(R.id.card_face); //首先feed_list_item.xml 2儿童的家长布局
holder.cardBack = view.findViewById(R.id.card_back); //第二feed_list_item.xml 2儿童的家长布局
holder.flipAnimation =新FlipAnimation(holder.cardFace,holder.cardBack);
view.setTag(保持器);
} 其他 {
支架=(AdvItemHolder)view.getTag();
}
holder.rotator.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
如果(!((布尔)v.getTag())。的booleanValue()){
v.setTag(真正的); //开关布尔
//你可以调用notifydatasetchanged显示的变化功能变化或将改变功能在这里
}其他{v.setTag(假); //开关布尔再次,如果它已经被点击}
}
}));
//我把这里 - (其他城市功能)的变化,使打算我呼吁notifydatasetchanged在onclick
//但它取决于你的preference
//查布尔,而不是来看是可见的..
如果(((布尔)view.findViewById(R.id.card_roretor).getTag())。的booleanValue()){
flipAnimation.reverse();
view.findViewById(R.id.card_roretor).startAnimation(holder.flipAnimation);
}
//改变功能的结束
返回查看;
}
...............................
私有静态类ArtItemHolder {
ImageView的形象;
TextView的pubdate的;
TextView的arTitle;
TextView的commentCount;
ImageView的转子;
查看cardFace,cardBack;
FlipAnimation flipAnimation;
}
I'm trying to show front and back face of each of my listview
item with Flip animation
. Animation works well, but the result of anim is being applied to other items also. And furthermore, the position of my items change when I scroll up and down. My code is as below:
public View getView(final int position, final View convertView, ViewGroup parent) {
ArtItemHolder holder;
View view = convertView;
if (view == null) {
LayoutInflater inflater = ((Activity) this.context).getLayoutInflater();
holder = new ArtItemHolder();
view = inflater.inflate(R.layout.feed_list_item, parent, false);
holder.image = (ImageView) view.findViewById(R.id.img_Image);
holder.pubDate = (TextView) view.findViewById(R.id.txt_puslishDate);
holder.arTitle = (TextView) view.findViewById(R.id.txt_arTitle);
holder.commentCount = (TextView) view.findViewById(R.id.txt_commentCount);
holder.rotator = (ImageView) view.findViewById(R.id.card_roretor);
holder.cardFace = view.findViewById(R.id.card_face);// first of 2 child parent layout of feed_list_item.xml
holder.cardBack = view.findViewById(R.id.card_back);// second of 2 child parent layout of feed_list_item.xml
view.setTag(holder);
} else {
holder = (AdvItemHolder) view.getTag();
}
holder.rotator.setOnClickListener(new MyFlipperListener(view, holder.cardFace, holder.cardBack));
return view;
}
private class MyFlipperListener implements OnClickListener{
View parent, frontFace, backFace;
public MyFlipperListener(View parent, View frontFace, View backFace) {
this.parent = parent;
this.frontFace = frontFace;
this.backFace = backFace;
}
public void onClick(View v) {
FlipAnimation flipAnimation = new FlipAnimation(frontFace, backFace);
if (frontFace.getVisibility() == View.GONE)
{
flipAnimation.reverse();
}
parent.startAnimation(flipAnimation);
}
}
private static class ArtItemHolder{
ImageView image;
TextView pubDate;
TextView arTitle;
TextView commentCount;
ImageView rotator;
View cardFace, cardBack;
}
My layout xml for items in listview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:id="@+id/card_face"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/feed_item_selector"
android:layout_margin="8dip"
android:padding="2dip">
########## MAIN CONTENT HERE ###########
</LinearLayout>
<LinearLayout
android:id="@+id/card_back"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/feed_item_selector"
android:layout_margin="8dip"
android:padding="2dip"
android:visibility="gone">
########## SOME INFO ABOUT MAIN CONTENT HERE ###########
</LinearLayout>
</LinearLayout>
UPDATE
FlipAnimation flipAnimation = new FlipAnimation(holder.cardFace, holder.cardBack);
holder.rotator.setOnClickListener(new MyFlipperListener(view, holder.cardFace, flipAnimation));
private class MyFlipperListener implements OnClickListener{
View parent, frontFace;
FlipAnimation flipAnimation;
public MyFlipperListener(View parent, View frontFace, FlipAnimation flip) {
this.parent = parent;
this.frontFace = frontFace;
this.flipAnimation = flip;
}
public void onClick(View v) {
if (frontFace.getVisibility() == View.GONE){
flipAnimation.reverse();
}
parent.startAnimation(flipAnimation);
}
}
解决方案
ayt check my solution...
public View getView(final int position, final View convertView, ViewGroup parent) {
ArtItemHolder holder;
View view = convertView;
if (view == null) {
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
holder = new ArtItemHolder();
view = inflater.inflate(R.layout.feed_list_item, parent, false);
holder.image = (ImageView) view.findViewById(R.id.img_Image);
holder.pubDate = (TextView) view.findViewById(R.id.txt_puslishDate);
holder.arTitle = (TextView) view.findViewById(R.id.txt_arTitle);
holder.commentCount = (TextView) view.findViewById(R.id.txt_commentCount);
holder.rotator = (ImageView) view.findViewById(R.id.card_roretor);
holder.rotator.setTag(false); // put a boolean here..
holder.cardFace = view.findViewById(R.id.card_face);// first of 2 child parent layout of feed_list_item.xml
holder.cardBack = view.findViewById(R.id.card_back);// second of 2 child parent layout of feed_list_item.xml
holder.flipAnimation = new FlipAnimation(holder.cardFace, holder.cardBack);
view.setTag(holder);
} else {
holder = (AdvItemHolder) view.getTag();
}
holder.rotator.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (!((Boolean) v.getTag()).booleanValue()){
v.setTag(true); // switch boolean
// you can either call notifydatasetchanged to show changes by the change function or put the change function here
}else{v.setTag(false); // switch boolean again if it has already been clicked}
}
}));
// i am putting the changes here-(change function) so intend i call notifydatasetchanged in the onclick
// but it depends on your preference
// check the boolean instead of view being visible..
if (((Boolean) view.findViewById(R.id.card_roretor).getTag()).booleanValue()){
flipAnimation.reverse();
view.findViewById(R.id.card_roretor).startAnimation(holder.flipAnimation);
}
// end of the change function
return view;
}
...............................
private static class ArtItemHolder{
ImageView image;
TextView pubDate;
TextView arTitle;
TextView commentCount;
ImageView rotator;
View cardFace, cardBack;
FlipAnimation flipAnimation;
}
这篇关于在Android的ListView项翻转动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文