繁体   English   中英

如何仅对回收站的一个字段进行动画处理

[英]how to animate only one field of a recyclerView item

我有一个RecyclerView ,其中包含ImageView1TextView1TextView2ImageView2 我想的是,应用程序运行时, textView2有一个动画slideInLeft无限,对于每一个项目recyclerView ,当你向下滚动,然后回来一个项目,动画重新开始。

我的XML中的TextView看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
 <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:textColor="@color/slideingText"
            android:textSize="18sp"
            android:layout_weight="2"
            android:layout_marginRight="3dp"
            android:text="this is some other text if you need this to be done you have to do it yourself"
            android:layout_gravity="center"
            android:singleLine="true"
            android:focusable="true"
            android:textStyle="bold"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:ellipsize="marquee"
            android:gravity="center"
            android:scrollHorizontally="true"
            android:id="@+id/currentShowTitle"/>

在我的RecyclerVew适配器中,我做了这样的事情:

setAnimation(holder.currentShowTitle,position);

哪里

 private void setAnimation(View viewToAnimate, int position)
    {
        if (position > lastPosition)
        {
            Animation animation = AnimationUtils.loadAnimation(context, android.R.anim.slide_in_left);
            viewToAnimate.startAnimation(animation);
            lastPosition = position;
        }
    }

我也用过

 @Override
    public void onViewDetachedFromWindow(ChannelsViewHolder holder) {
        super.onViewDetachedFromWindow(holder);
        ((ChannelsViewHolder)holder).clearAnimation();
    }

问题在于,当应用运行时,它会像我只想要第一项一样进行动画处理;当我向下滚动并返回时,动画不会再次开始。 有人知道该怎么做吗?

尝试在以下方法中调用您的方法:

public void onBindViewHolder(mAdapter.MyViewHolder holder, int position)
{
setAnimation(//pass parameters(position etc...));
}

OnBindViewHolder编写以下代码

if (position == 0) {
     holder.yourView.startAnimation(Your_animation);
}

如果要在每次滚动时进行动画处理。 删除要保存最后位置的位置检查,然后转到这里:

 private void setAnimation(View viewToAnimate, int position)
{

        Animation animation = AnimationUtils.loadAnimation(context, android.R.anim.slide_in_left);
        viewToAnimate.startAnimation(animation);

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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