Adding a custom view to a Recyclerview listGet root view from current activityAndroid “Only the original thread that created a view hierarchy can touch its views.”What is the main purpose of setTag() getTag() methods of View?Android — SurfaceView assigned from findViewById(R…) won't allow access to custom fieldsonMeasure custom view explanationRecyclerView onClickHow to add dividers and spaces between items in RecyclerView?Why doesn't RecyclerView have onItemClickListener()?How to create RecyclerView with multiple view type?How to implement endless list with RecyclerView?

Why different specifications for telescopes and binoculars?

When do flights get cancelled due to fog?

What is a writing material that persists forever or for a long time?

Run Bash scripts in folder all at the same time

VHF 50 Ω Antenna Over 75 Ω TV Coax

Why does the Antonov AN-225 not have any winglets?

Why do airports remove/realign runways?

When I press the space bar it deletes the letters in front of it

First Entry Member State schengen visa

What was the profession 芸者 (female entertainer) called in Russia?

Can you cast the Shape Water spell without an existing obvious pool of water?

Number of states in taxi environment (Dietterich 2000)

Did depressed people far more accurately estimate how many monsters they killed in a video game?

Generalized Behrend version for Grothendieck-Lefschetz trace formula

What does the multimeter dial do internally?

Estimates on number of topologies on a finite set

Why does Trump want a citizenship question on the census?

What are the consequences for a developed nation to not accept any refugees?

Deck of Cards with Shuffle and Sort functionality

Optimization models for portfolio optimization

Why was such an unrevealing title originally chosen and then changed for some International markets?

What factors could lead to bishops establishing monastic armies?

My previous employer committed a severe violation of the law and is also being sued by me. How do I explain the situation to future employers?

Did Rabbi Akiva accept arguments from ignorance?



Adding a custom view to a Recyclerview list


Get root view from current activityAndroid “Only the original thread that created a view hierarchy can touch its views.”What is the main purpose of setTag() getTag() methods of View?Android — SurfaceView assigned from findViewById(R…) won't allow access to custom fieldsonMeasure custom view explanationRecyclerView onClickHow to add dividers and spaces between items in RecyclerView?Why doesn't RecyclerView have onItemClickListener()?How to create RecyclerView with multiple view type?How to implement endless list with RecyclerView?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a custom view that has a circle animation using a runnable (circle bounces between edges of the screen horizontally). This is working outside of the recyclerview, but what I'm having trouble with is adding the circle animation inside the list.



Circle Animation Class



public class CircleAnimationView extends View 

Handler handler = new Handler(Looper.getMainLooper());
int mCircleRadius, mCircleSpeed, mCircleX, mCenterX, mCircleDirection,
mColor;
Paint mBodyPaint;
boolean initPos = true;
final long COUNT_INTERVAL = 16L;

public CircleAnimationView(Context context)
this(context,null);


public CircleAnimationView(Context context, @Nullable AttributeSet
attrs)
super(context,attrs);

mCircleRadius = (int)dpToPx(10);

TypedArray array = context.obtainStyledAttributes(attrs,
R.styleable.CircleAnimationView);

array.recycle();

initPaints();

mUpdateCircleRunnable.run();


private void initPaints()
mBodyPaint = new Paint();
mBodyPaint.setColor(Color.BLACK);


@Override
protected void onDraw(Canvas canvas)
super.onDraw(canvas);
mCenterX = getWidth()/2;
if (initPos)
canvas.drawCircle(mCenterX,100,mCircleRadius,mBodyPaint);
initPos = false;
canvas.drawCircle(mCircleX,100,mCircleRadius,mBodyPaint);


private float dpToPx(int dpValue)
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
dpValue, getResources().getDisplayMetrics());


public void addRadius(int radius)
mCircleRadius = radius;


public void addSpeed(int speed)
mCircleSpeed = speed;


public void addColor(int color)
mColor = color;


Runnable mUpdateCircleRunnable = () -> setmUpdateCircleRunnable();

public void setmUpdateCircleRunnable()



Adapter Class



public class CircleAnimationAdapter extends 
RecyclerView.Adapter<RecyclerView.ViewHolder>

Context mContext;
private List<Circle> properties;
View.OnClickListener mClickListener;
CircleAnimationView circle;

private int mSelectedPosition = Adapter.NO_SELECTION;

public CircleAnimationAdapter(Context context, List<Circle> circleList,
View.OnClickListener listener)
mContext = context;
properties = circleList;
mClickListener = listener;


@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int
viewType)
View view = View.inflate(mContext,
R.layout.fragment_circleanimation, null);
RecyclerViewHolder holder = new RecyclerViewHolder(view);

return holder;


@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int
position)
RecyclerViewHolder viewHolder = (RecyclerViewHolder) holder;
Canvas canvas = new Canvas();
((RecyclerViewHolder) holder).circle.draw(canvas);

circle = new CircleAnimationView(mContext);
circle.addRadius(properties.get(position).getRadius());
circle.addSpeed(properties.get(position).getSpeed());
circle.addColor(properties.get(position).getColor());

viewHolder.itemView.setOnClickListener(mClickListener);
viewHolder.itemView.setTag(position);


@Override
public int getItemCount()
return properties.size();


public void setSelectedPosition(int position)
mSelectedPosition = position == mSelectedPosition ?
Adapter.NO_SELECTION : position;
notifyDataSetChanged();


public int getSelectedPosition()
return mSelectedPosition;


public boolean isPositionSelected()
return mSelectedPosition != Adapter.NO_SELECTION;


private class RecyclerViewHolder extends RecyclerView.ViewHolder

CircleAnimationView circle;

RecyclerViewHolder(View view)
super(view);
circle = new CircleAnimationView(mContext);


public void bindCircle(Circle objCircle)
//circle.draw();
circle.invalidate();





Fragment Class



public class CircleAnimationFragment extends Fragment 

RecyclerView mRecyclerView;
CircleAnimationAdapter mAdapter;

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
super.onActivityCreated(savedInstanceState);
configureListView();
mRecyclerView.setLayoutManager(new
LinearLayoutManager(getActivity()));
mRecyclerView.setAdapter(mAdapter);


@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
View view = inflater.inflate(R.layout.fragment_circleanimation_list,
container, false);
mRecyclerView = view.findViewById(R.id.list);

return view;


private void configureListView()
List<CircleAnimationView> circles = new ArrayList<>(1);
circles.add(new CircleAnimationView(getActivity(),null));




XML main



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/example"
android:id="@+id/exampleHead"
android:gravity="center"
android:layout_centerHorizontal="true"/>

<com.mdadi.circleanimation.CircleAnimationView
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_below="@+id/exampleHead"
android:id="@+id/example"/>

<TextView
android:id="@+id/customHead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/example"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/custom" />

<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list"
android:name="com.mdadi.circleanimation.CircleAnimationFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context=".CircleAnimationFragment"
tools:listitem="@layout/fragment_circleanimation"
android:layout_below="@+id/customHead"
android:layout_centerHorizontal="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radius"
android:labelFor="@+id/radius_input"
android:id="@+id/radius_label"
android:layout_alignParentStart="true"
android:layout_alignBottom="@+id/speed_label"/>

<EditText
android:layout_width="50dp"
android:layout_height="wrap_content"
android:inputType="number"
android:id="@+id/radius_input"
android:layout_toEndOf="@+id/radius_label"
android:layout_alignBottom="@+id/speed_label"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/speed"
android:labelFor="@+id/speed_input"
android:id="@+id/speed_label"
android:layout_above="@+id/btn_add"
android:layout_toStartOf="@+id/speed_input"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/color"
android:layout_alignParentBottom="true"
android:id="@+id/color_label"
android:layout_marginBottom="5dp"/>

<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/red"
android:background="@color/red"
android:layout_centerInParent="true"
android:layout_toEndOf="@+id/color_label"
android:layout_alignParentBottom="true"
android:layout_marginStart="10dp"
android:layout_marginBottom="5dp"/>

<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/orange"
android:background="@color/orange"
android:layout_centerInParent="true"
android:layout_toEndOf="@+id/red"
android:layout_alignParentBottom="true"
android:layout_marginStart="10dp"
android:layout_marginBottom="5dp"/>

<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/green"
android:background="@color/green"
android:layout_centerInParent="true"
android:layout_toEndOf="@+id/orange"
android:layout_alignParentBottom="true"
android:layout_marginStart="10dp"
android:layout_marginBottom="5dp"/>

<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/blue"
android:background="@color/blue"
android:layout_centerInParent="true"
android:layout_toEndOf="@+id/green"
android:layout_alignParentBottom="true"
android:layout_marginStart="10dp"
android:layout_marginBottom="5dp"/>

<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/yellow"
android:background="@color/yellow"
android:layout_centerInParent="true"
android:layout_toEndOf="@+id/blue"
android:layout_alignParentBottom="true"
android:layout_marginStart="10dp"
android:layout_marginBottom="5dp"/>

<EditText
android:layout_width="50dp"
android:layout_height="wrap_content"
android:inputType="number"
android:id="@+id/speed_input"
android:layout_alignParentEnd="true"
android:layout_above="@+id/btn_add"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_add"
android:text="@string/add"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"/>

<!--adder for circle speed-->

</RelativeLayout>


Any help would be appreciated on this, first time doing this type of program and pretty desperate...










share|improve this question




























    0















    I have a custom view that has a circle animation using a runnable (circle bounces between edges of the screen horizontally). This is working outside of the recyclerview, but what I'm having trouble with is adding the circle animation inside the list.



    Circle Animation Class



    public class CircleAnimationView extends View 

    Handler handler = new Handler(Looper.getMainLooper());
    int mCircleRadius, mCircleSpeed, mCircleX, mCenterX, mCircleDirection,
    mColor;
    Paint mBodyPaint;
    boolean initPos = true;
    final long COUNT_INTERVAL = 16L;

    public CircleAnimationView(Context context)
    this(context,null);


    public CircleAnimationView(Context context, @Nullable AttributeSet
    attrs)
    super(context,attrs);

    mCircleRadius = (int)dpToPx(10);

    TypedArray array = context.obtainStyledAttributes(attrs,
    R.styleable.CircleAnimationView);

    array.recycle();

    initPaints();

    mUpdateCircleRunnable.run();


    private void initPaints()
    mBodyPaint = new Paint();
    mBodyPaint.setColor(Color.BLACK);


    @Override
    protected void onDraw(Canvas canvas)
    super.onDraw(canvas);
    mCenterX = getWidth()/2;
    if (initPos)
    canvas.drawCircle(mCenterX,100,mCircleRadius,mBodyPaint);
    initPos = false;
    canvas.drawCircle(mCircleX,100,mCircleRadius,mBodyPaint);


    private float dpToPx(int dpValue)
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
    dpValue, getResources().getDisplayMetrics());


    public void addRadius(int radius)
    mCircleRadius = radius;


    public void addSpeed(int speed)
    mCircleSpeed = speed;


    public void addColor(int color)
    mColor = color;


    Runnable mUpdateCircleRunnable = () -> setmUpdateCircleRunnable();

    public void setmUpdateCircleRunnable()



    Adapter Class



    public class CircleAnimationAdapter extends 
    RecyclerView.Adapter<RecyclerView.ViewHolder>

    Context mContext;
    private List<Circle> properties;
    View.OnClickListener mClickListener;
    CircleAnimationView circle;

    private int mSelectedPosition = Adapter.NO_SELECTION;

    public CircleAnimationAdapter(Context context, List<Circle> circleList,
    View.OnClickListener listener)
    mContext = context;
    properties = circleList;
    mClickListener = listener;


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int
    viewType)
    View view = View.inflate(mContext,
    R.layout.fragment_circleanimation, null);
    RecyclerViewHolder holder = new RecyclerViewHolder(view);

    return holder;


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int
    position)
    RecyclerViewHolder viewHolder = (RecyclerViewHolder) holder;
    Canvas canvas = new Canvas();
    ((RecyclerViewHolder) holder).circle.draw(canvas);

    circle = new CircleAnimationView(mContext);
    circle.addRadius(properties.get(position).getRadius());
    circle.addSpeed(properties.get(position).getSpeed());
    circle.addColor(properties.get(position).getColor());

    viewHolder.itemView.setOnClickListener(mClickListener);
    viewHolder.itemView.setTag(position);


    @Override
    public int getItemCount()
    return properties.size();


    public void setSelectedPosition(int position)
    mSelectedPosition = position == mSelectedPosition ?
    Adapter.NO_SELECTION : position;
    notifyDataSetChanged();


    public int getSelectedPosition()
    return mSelectedPosition;


    public boolean isPositionSelected()
    return mSelectedPosition != Adapter.NO_SELECTION;


    private class RecyclerViewHolder extends RecyclerView.ViewHolder

    CircleAnimationView circle;

    RecyclerViewHolder(View view)
    super(view);
    circle = new CircleAnimationView(mContext);


    public void bindCircle(Circle objCircle)
    //circle.draw();
    circle.invalidate();





    Fragment Class



    public class CircleAnimationFragment extends Fragment 

    RecyclerView mRecyclerView;
    CircleAnimationAdapter mAdapter;

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState)
    super.onActivityCreated(savedInstanceState);
    configureListView();
    mRecyclerView.setLayoutManager(new
    LinearLayoutManager(getActivity()));
    mRecyclerView.setAdapter(mAdapter);


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState)
    View view = inflater.inflate(R.layout.fragment_circleanimation_list,
    container, false);
    mRecyclerView = view.findViewById(R.id.list);

    return view;


    private void configureListView()
    List<CircleAnimationView> circles = new ArrayList<>(1);
    circles.add(new CircleAnimationView(getActivity(),null));




    XML main



    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/example"
    android:id="@+id/exampleHead"
    android:gravity="center"
    android:layout_centerHorizontal="true"/>

    <com.mdadi.circleanimation.CircleAnimationView
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:layout_below="@+id/exampleHead"
    android:id="@+id/example"/>

    <TextView
    android:id="@+id/customHead"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/example"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:text="@string/custom" />

    <android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/list"
    android:name="com.mdadi.circleanimation.CircleAnimationFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    app:layoutManager="LinearLayoutManager"
    tools:context=".CircleAnimationFragment"
    tools:listitem="@layout/fragment_circleanimation"
    android:layout_below="@+id/customHead"
    android:layout_centerHorizontal="true" />

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/radius"
    android:labelFor="@+id/radius_input"
    android:id="@+id/radius_label"
    android:layout_alignParentStart="true"
    android:layout_alignBottom="@+id/speed_label"/>

    <EditText
    android:layout_width="50dp"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:id="@+id/radius_input"
    android:layout_toEndOf="@+id/radius_label"
    android:layout_alignBottom="@+id/speed_label"/>

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/speed"
    android:labelFor="@+id/speed_input"
    android:id="@+id/speed_label"
    android:layout_above="@+id/btn_add"
    android:layout_toStartOf="@+id/speed_input"/>

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/color"
    android:layout_alignParentBottom="true"
    android:id="@+id/color_label"
    android:layout_marginBottom="5dp"/>

    <Button
    android:layout_width="25dp"
    android:layout_height="25dp"
    android:id="@+id/red"
    android:background="@color/red"
    android:layout_centerInParent="true"
    android:layout_toEndOf="@+id/color_label"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="10dp"
    android:layout_marginBottom="5dp"/>

    <Button
    android:layout_width="25dp"
    android:layout_height="25dp"
    android:id="@+id/orange"
    android:background="@color/orange"
    android:layout_centerInParent="true"
    android:layout_toEndOf="@+id/red"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="10dp"
    android:layout_marginBottom="5dp"/>

    <Button
    android:layout_width="25dp"
    android:layout_height="25dp"
    android:id="@+id/green"
    android:background="@color/green"
    android:layout_centerInParent="true"
    android:layout_toEndOf="@+id/orange"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="10dp"
    android:layout_marginBottom="5dp"/>

    <Button
    android:layout_width="25dp"
    android:layout_height="25dp"
    android:id="@+id/blue"
    android:background="@color/blue"
    android:layout_centerInParent="true"
    android:layout_toEndOf="@+id/green"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="10dp"
    android:layout_marginBottom="5dp"/>

    <Button
    android:layout_width="25dp"
    android:layout_height="25dp"
    android:id="@+id/yellow"
    android:background="@color/yellow"
    android:layout_centerInParent="true"
    android:layout_toEndOf="@+id/blue"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="10dp"
    android:layout_marginBottom="5dp"/>

    <EditText
    android:layout_width="50dp"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:id="@+id/speed_input"
    android:layout_alignParentEnd="true"
    android:layout_above="@+id/btn_add"/>

    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/btn_add"
    android:text="@string/add"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"/>

    <!--adder for circle speed-->

    </RelativeLayout>


    Any help would be appreciated on this, first time doing this type of program and pretty desperate...










    share|improve this question
























      0












      0








      0








      I have a custom view that has a circle animation using a runnable (circle bounces between edges of the screen horizontally). This is working outside of the recyclerview, but what I'm having trouble with is adding the circle animation inside the list.



      Circle Animation Class



      public class CircleAnimationView extends View 

      Handler handler = new Handler(Looper.getMainLooper());
      int mCircleRadius, mCircleSpeed, mCircleX, mCenterX, mCircleDirection,
      mColor;
      Paint mBodyPaint;
      boolean initPos = true;
      final long COUNT_INTERVAL = 16L;

      public CircleAnimationView(Context context)
      this(context,null);


      public CircleAnimationView(Context context, @Nullable AttributeSet
      attrs)
      super(context,attrs);

      mCircleRadius = (int)dpToPx(10);

      TypedArray array = context.obtainStyledAttributes(attrs,
      R.styleable.CircleAnimationView);

      array.recycle();

      initPaints();

      mUpdateCircleRunnable.run();


      private void initPaints()
      mBodyPaint = new Paint();
      mBodyPaint.setColor(Color.BLACK);


      @Override
      protected void onDraw(Canvas canvas)
      super.onDraw(canvas);
      mCenterX = getWidth()/2;
      if (initPos)
      canvas.drawCircle(mCenterX,100,mCircleRadius,mBodyPaint);
      initPos = false;
      canvas.drawCircle(mCircleX,100,mCircleRadius,mBodyPaint);


      private float dpToPx(int dpValue)
      return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
      dpValue, getResources().getDisplayMetrics());


      public void addRadius(int radius)
      mCircleRadius = radius;


      public void addSpeed(int speed)
      mCircleSpeed = speed;


      public void addColor(int color)
      mColor = color;


      Runnable mUpdateCircleRunnable = () -> setmUpdateCircleRunnable();

      public void setmUpdateCircleRunnable()



      Adapter Class



      public class CircleAnimationAdapter extends 
      RecyclerView.Adapter<RecyclerView.ViewHolder>

      Context mContext;
      private List<Circle> properties;
      View.OnClickListener mClickListener;
      CircleAnimationView circle;

      private int mSelectedPosition = Adapter.NO_SELECTION;

      public CircleAnimationAdapter(Context context, List<Circle> circleList,
      View.OnClickListener listener)
      mContext = context;
      properties = circleList;
      mClickListener = listener;


      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int
      viewType)
      View view = View.inflate(mContext,
      R.layout.fragment_circleanimation, null);
      RecyclerViewHolder holder = new RecyclerViewHolder(view);

      return holder;


      @Override
      public void onBindViewHolder(RecyclerView.ViewHolder holder, int
      position)
      RecyclerViewHolder viewHolder = (RecyclerViewHolder) holder;
      Canvas canvas = new Canvas();
      ((RecyclerViewHolder) holder).circle.draw(canvas);

      circle = new CircleAnimationView(mContext);
      circle.addRadius(properties.get(position).getRadius());
      circle.addSpeed(properties.get(position).getSpeed());
      circle.addColor(properties.get(position).getColor());

      viewHolder.itemView.setOnClickListener(mClickListener);
      viewHolder.itemView.setTag(position);


      @Override
      public int getItemCount()
      return properties.size();


      public void setSelectedPosition(int position)
      mSelectedPosition = position == mSelectedPosition ?
      Adapter.NO_SELECTION : position;
      notifyDataSetChanged();


      public int getSelectedPosition()
      return mSelectedPosition;


      public boolean isPositionSelected()
      return mSelectedPosition != Adapter.NO_SELECTION;


      private class RecyclerViewHolder extends RecyclerView.ViewHolder

      CircleAnimationView circle;

      RecyclerViewHolder(View view)
      super(view);
      circle = new CircleAnimationView(mContext);


      public void bindCircle(Circle objCircle)
      //circle.draw();
      circle.invalidate();





      Fragment Class



      public class CircleAnimationFragment extends Fragment 

      RecyclerView mRecyclerView;
      CircleAnimationAdapter mAdapter;

      @Override
      public void onActivityCreated(@Nullable Bundle savedInstanceState)
      super.onActivityCreated(savedInstanceState);
      configureListView();
      mRecyclerView.setLayoutManager(new
      LinearLayoutManager(getActivity()));
      mRecyclerView.setAdapter(mAdapter);


      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState)
      View view = inflater.inflate(R.layout.fragment_circleanimation_list,
      container, false);
      mRecyclerView = view.findViewById(R.id.list);

      return view;


      private void configureListView()
      List<CircleAnimationView> circles = new ArrayList<>(1);
      circles.add(new CircleAnimationView(getActivity(),null));




      XML main



      <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout android:layout_height="match_parent"
      android:layout_width="match_parent"
      xmlns:android="http://schemas.android.com/apk/res/android">

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/example"
      android:id="@+id/exampleHead"
      android:gravity="center"
      android:layout_centerHorizontal="true"/>

      <com.mdadi.circleanimation.CircleAnimationView
      android:layout_width="match_parent"
      android:layout_height="80dp"
      android:layout_below="@+id/exampleHead"
      android:id="@+id/example"/>

      <TextView
      android:id="@+id/customHead"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/example"
      android:layout_centerHorizontal="true"
      android:gravity="center"
      android:text="@string/custom" />

      <android.support.v7.widget.RecyclerView
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/list"
      android:name="com.mdadi.circleanimation.CircleAnimationFragment"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginLeft="16dp"
      android:layout_marginRight="16dp"
      app:layoutManager="LinearLayoutManager"
      tools:context=".CircleAnimationFragment"
      tools:listitem="@layout/fragment_circleanimation"
      android:layout_below="@+id/customHead"
      android:layout_centerHorizontal="true" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/radius"
      android:labelFor="@+id/radius_input"
      android:id="@+id/radius_label"
      android:layout_alignParentStart="true"
      android:layout_alignBottom="@+id/speed_label"/>

      <EditText
      android:layout_width="50dp"
      android:layout_height="wrap_content"
      android:inputType="number"
      android:id="@+id/radius_input"
      android:layout_toEndOf="@+id/radius_label"
      android:layout_alignBottom="@+id/speed_label"/>

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/speed"
      android:labelFor="@+id/speed_input"
      android:id="@+id/speed_label"
      android:layout_above="@+id/btn_add"
      android:layout_toStartOf="@+id/speed_input"/>

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/color"
      android:layout_alignParentBottom="true"
      android:id="@+id/color_label"
      android:layout_marginBottom="5dp"/>

      <Button
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:id="@+id/red"
      android:background="@color/red"
      android:layout_centerInParent="true"
      android:layout_toEndOf="@+id/color_label"
      android:layout_alignParentBottom="true"
      android:layout_marginStart="10dp"
      android:layout_marginBottom="5dp"/>

      <Button
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:id="@+id/orange"
      android:background="@color/orange"
      android:layout_centerInParent="true"
      android:layout_toEndOf="@+id/red"
      android:layout_alignParentBottom="true"
      android:layout_marginStart="10dp"
      android:layout_marginBottom="5dp"/>

      <Button
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:id="@+id/green"
      android:background="@color/green"
      android:layout_centerInParent="true"
      android:layout_toEndOf="@+id/orange"
      android:layout_alignParentBottom="true"
      android:layout_marginStart="10dp"
      android:layout_marginBottom="5dp"/>

      <Button
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:id="@+id/blue"
      android:background="@color/blue"
      android:layout_centerInParent="true"
      android:layout_toEndOf="@+id/green"
      android:layout_alignParentBottom="true"
      android:layout_marginStart="10dp"
      android:layout_marginBottom="5dp"/>

      <Button
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:id="@+id/yellow"
      android:background="@color/yellow"
      android:layout_centerInParent="true"
      android:layout_toEndOf="@+id/blue"
      android:layout_alignParentBottom="true"
      android:layout_marginStart="10dp"
      android:layout_marginBottom="5dp"/>

      <EditText
      android:layout_width="50dp"
      android:layout_height="wrap_content"
      android:inputType="number"
      android:id="@+id/speed_input"
      android:layout_alignParentEnd="true"
      android:layout_above="@+id/btn_add"/>

      <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/btn_add"
      android:text="@string/add"
      android:layout_alignParentEnd="true"
      android:layout_alignParentBottom="true"/>

      <!--adder for circle speed-->

      </RelativeLayout>


      Any help would be appreciated on this, first time doing this type of program and pretty desperate...










      share|improve this question














      I have a custom view that has a circle animation using a runnable (circle bounces between edges of the screen horizontally). This is working outside of the recyclerview, but what I'm having trouble with is adding the circle animation inside the list.



      Circle Animation Class



      public class CircleAnimationView extends View 

      Handler handler = new Handler(Looper.getMainLooper());
      int mCircleRadius, mCircleSpeed, mCircleX, mCenterX, mCircleDirection,
      mColor;
      Paint mBodyPaint;
      boolean initPos = true;
      final long COUNT_INTERVAL = 16L;

      public CircleAnimationView(Context context)
      this(context,null);


      public CircleAnimationView(Context context, @Nullable AttributeSet
      attrs)
      super(context,attrs);

      mCircleRadius = (int)dpToPx(10);

      TypedArray array = context.obtainStyledAttributes(attrs,
      R.styleable.CircleAnimationView);

      array.recycle();

      initPaints();

      mUpdateCircleRunnable.run();


      private void initPaints()
      mBodyPaint = new Paint();
      mBodyPaint.setColor(Color.BLACK);


      @Override
      protected void onDraw(Canvas canvas)
      super.onDraw(canvas);
      mCenterX = getWidth()/2;
      if (initPos)
      canvas.drawCircle(mCenterX,100,mCircleRadius,mBodyPaint);
      initPos = false;
      canvas.drawCircle(mCircleX,100,mCircleRadius,mBodyPaint);


      private float dpToPx(int dpValue)
      return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
      dpValue, getResources().getDisplayMetrics());


      public void addRadius(int radius)
      mCircleRadius = radius;


      public void addSpeed(int speed)
      mCircleSpeed = speed;


      public void addColor(int color)
      mColor = color;


      Runnable mUpdateCircleRunnable = () -> setmUpdateCircleRunnable();

      public void setmUpdateCircleRunnable()



      Adapter Class



      public class CircleAnimationAdapter extends 
      RecyclerView.Adapter<RecyclerView.ViewHolder>

      Context mContext;
      private List<Circle> properties;
      View.OnClickListener mClickListener;
      CircleAnimationView circle;

      private int mSelectedPosition = Adapter.NO_SELECTION;

      public CircleAnimationAdapter(Context context, List<Circle> circleList,
      View.OnClickListener listener)
      mContext = context;
      properties = circleList;
      mClickListener = listener;


      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int
      viewType)
      View view = View.inflate(mContext,
      R.layout.fragment_circleanimation, null);
      RecyclerViewHolder holder = new RecyclerViewHolder(view);

      return holder;


      @Override
      public void onBindViewHolder(RecyclerView.ViewHolder holder, int
      position)
      RecyclerViewHolder viewHolder = (RecyclerViewHolder) holder;
      Canvas canvas = new Canvas();
      ((RecyclerViewHolder) holder).circle.draw(canvas);

      circle = new CircleAnimationView(mContext);
      circle.addRadius(properties.get(position).getRadius());
      circle.addSpeed(properties.get(position).getSpeed());
      circle.addColor(properties.get(position).getColor());

      viewHolder.itemView.setOnClickListener(mClickListener);
      viewHolder.itemView.setTag(position);


      @Override
      public int getItemCount()
      return properties.size();


      public void setSelectedPosition(int position)
      mSelectedPosition = position == mSelectedPosition ?
      Adapter.NO_SELECTION : position;
      notifyDataSetChanged();


      public int getSelectedPosition()
      return mSelectedPosition;


      public boolean isPositionSelected()
      return mSelectedPosition != Adapter.NO_SELECTION;


      private class RecyclerViewHolder extends RecyclerView.ViewHolder

      CircleAnimationView circle;

      RecyclerViewHolder(View view)
      super(view);
      circle = new CircleAnimationView(mContext);


      public void bindCircle(Circle objCircle)
      //circle.draw();
      circle.invalidate();





      Fragment Class



      public class CircleAnimationFragment extends Fragment 

      RecyclerView mRecyclerView;
      CircleAnimationAdapter mAdapter;

      @Override
      public void onActivityCreated(@Nullable Bundle savedInstanceState)
      super.onActivityCreated(savedInstanceState);
      configureListView();
      mRecyclerView.setLayoutManager(new
      LinearLayoutManager(getActivity()));
      mRecyclerView.setAdapter(mAdapter);


      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState)
      View view = inflater.inflate(R.layout.fragment_circleanimation_list,
      container, false);
      mRecyclerView = view.findViewById(R.id.list);

      return view;


      private void configureListView()
      List<CircleAnimationView> circles = new ArrayList<>(1);
      circles.add(new CircleAnimationView(getActivity(),null));




      XML main



      <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout android:layout_height="match_parent"
      android:layout_width="match_parent"
      xmlns:android="http://schemas.android.com/apk/res/android">

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/example"
      android:id="@+id/exampleHead"
      android:gravity="center"
      android:layout_centerHorizontal="true"/>

      <com.mdadi.circleanimation.CircleAnimationView
      android:layout_width="match_parent"
      android:layout_height="80dp"
      android:layout_below="@+id/exampleHead"
      android:id="@+id/example"/>

      <TextView
      android:id="@+id/customHead"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/example"
      android:layout_centerHorizontal="true"
      android:gravity="center"
      android:text="@string/custom" />

      <android.support.v7.widget.RecyclerView
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/list"
      android:name="com.mdadi.circleanimation.CircleAnimationFragment"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginLeft="16dp"
      android:layout_marginRight="16dp"
      app:layoutManager="LinearLayoutManager"
      tools:context=".CircleAnimationFragment"
      tools:listitem="@layout/fragment_circleanimation"
      android:layout_below="@+id/customHead"
      android:layout_centerHorizontal="true" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/radius"
      android:labelFor="@+id/radius_input"
      android:id="@+id/radius_label"
      android:layout_alignParentStart="true"
      android:layout_alignBottom="@+id/speed_label"/>

      <EditText
      android:layout_width="50dp"
      android:layout_height="wrap_content"
      android:inputType="number"
      android:id="@+id/radius_input"
      android:layout_toEndOf="@+id/radius_label"
      android:layout_alignBottom="@+id/speed_label"/>

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/speed"
      android:labelFor="@+id/speed_input"
      android:id="@+id/speed_label"
      android:layout_above="@+id/btn_add"
      android:layout_toStartOf="@+id/speed_input"/>

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/color"
      android:layout_alignParentBottom="true"
      android:id="@+id/color_label"
      android:layout_marginBottom="5dp"/>

      <Button
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:id="@+id/red"
      android:background="@color/red"
      android:layout_centerInParent="true"
      android:layout_toEndOf="@+id/color_label"
      android:layout_alignParentBottom="true"
      android:layout_marginStart="10dp"
      android:layout_marginBottom="5dp"/>

      <Button
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:id="@+id/orange"
      android:background="@color/orange"
      android:layout_centerInParent="true"
      android:layout_toEndOf="@+id/red"
      android:layout_alignParentBottom="true"
      android:layout_marginStart="10dp"
      android:layout_marginBottom="5dp"/>

      <Button
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:id="@+id/green"
      android:background="@color/green"
      android:layout_centerInParent="true"
      android:layout_toEndOf="@+id/orange"
      android:layout_alignParentBottom="true"
      android:layout_marginStart="10dp"
      android:layout_marginBottom="5dp"/>

      <Button
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:id="@+id/blue"
      android:background="@color/blue"
      android:layout_centerInParent="true"
      android:layout_toEndOf="@+id/green"
      android:layout_alignParentBottom="true"
      android:layout_marginStart="10dp"
      android:layout_marginBottom="5dp"/>

      <Button
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:id="@+id/yellow"
      android:background="@color/yellow"
      android:layout_centerInParent="true"
      android:layout_toEndOf="@+id/blue"
      android:layout_alignParentBottom="true"
      android:layout_marginStart="10dp"
      android:layout_marginBottom="5dp"/>

      <EditText
      android:layout_width="50dp"
      android:layout_height="wrap_content"
      android:inputType="number"
      android:id="@+id/speed_input"
      android:layout_alignParentEnd="true"
      android:layout_above="@+id/btn_add"/>

      <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/btn_add"
      android:text="@string/add"
      android:layout_alignParentEnd="true"
      android:layout_alignParentBottom="true"/>

      <!--adder for circle speed-->

      </RelativeLayout>


      Any help would be appreciated on this, first time doing this type of program and pretty desperate...







      android view android-animation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 23:13









      Michael DadiMichael Dadi

      1138 bronze badges




      1138 bronze badges






















          0






          active

          oldest

          votes










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347720%2fadding-a-custom-view-to-a-recyclerview-list%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347720%2fadding-a-custom-view-to-a-recyclerview-list%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현