Android 如何仅为recyclerView项的一个字段设置动画

Android 如何仅为recyclerView项的一个字段设置动画,android,animation,android-recyclerview,Android,Animation,Android Recyclerview,我有一个RecyclerView项目,其中包含ImageView1,TextView1,TextView2,ImageView2。我希望当应用程序运行时,textView2为recyclerView的每一项都有一个无限左移的动画幻灯片,当您向下滚动并返回到某一项时,动画将重新开始 xml中的我的TextView如下所示: <?xml version="1.0" encoding="utf-8"?> <TextView android:layout_wi

我有一个
RecyclerView
项目,其中包含
ImageView1
TextView1
TextView2
ImageView2
。我希望当应用程序运行时,
textView2
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"/>
在哪里

我也用过

 @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...));
}

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

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

OnBindViewHolder
中编写以下代码

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

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

}

如果要在每次滚动时设置动画。删除保留用于存储上一个位置的位置检查,然后执行以下操作:

 private void setAnimation(View viewToAnimate, int position)
{

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

}