asked    Dean     2018-10-22       android       72 view        1 Answer

[SOLVED] Animate views inside Recyclerview

I am animating a RecyclerView and everything is working fine except that the views inside the RecyclerView are not showing properly.

Using common anim XML

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<translate
    android:fromXDelta="-100%p"
    android:toXDelta="0"
    android:repeatCount="infinite"
    android:duration="3000"/>

//IS WORKING FINE, MOVES RECYCLERVIEW ACROSS SCREEN !

Code for Recyclerview

Animation animLinear;

//OnCreate
recyclerView = findViewById(R.id.item_list);    
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true));
recyclerView.setAdapter(new Adapter_Main_Markets());
recyclerView.startAnimation(animLinear);

So, what's happening is the visible view of the recylerview is moving across the screen. I would like some help with moving the views inside the screen across the RecyclerView but I have no idea how to get the views inside the recyclerview properly.

//Adapter Main Markets
@Override
public void onBindViewHolder(@NonNull Adapter_Main_Markets.MyViewHolder holder, int position) {
    holder.mIdView.setText("" + market_list[position]);
    holder.mPriceView.setText("$ " + int_list[position]);
    holder.mChangeView.setText(change_list[position]);

}

Will I need a loop for the views in the adapter? Maybe set animation there? Any help would be appreciated.

This is RecyclerView

Item A Item B Item C Item D Item E.

What actually shows on screen in the visible area is Item A Item B Item C.

So, of course, the visible "Item A Item B Item C" goes across the screen but that is not what I want.

I want Item A to go across the screen then Item B the Item C, then D, then E.

  1 Answer  

        answered    Dorothy     2018-10-22      

If you want to animate views inside RecyclerView then you need to animate itemview inside ViewHolder constructor like this,

class `Your view holder class` extends RecyclerView.ViewHolder {

    `Constructor of your class`(View view) {
        super(view);
        //This piece of code will animate your itemview inside recyclerview
        new Handler().postDelayed(() -> {
            view.setVisibility(View.VISIBLE);
            view.startAnimation(AnimationUtils.loadAnimation(view.getContext(), android.R.anim.fade_in // Change your anim file here));
        }, 100);
        setIsRecyclable(true);// Just to ensure that everytime view gets invisible, it should be recycled for next time recreation.
    }
}

Next thing is to remove repeat count from your anim.xml

Remove android:repeatCount="infinite" this so that view will animate only once it gets visible.





Your Answer





 2018-10-22         Brady

Laravel: Expression #3 of SELECT list is not in GROUP BY (Querying a Many-to-Many relationship)

I got a project with the Models Menu and User, which are in a Many-to-Many relationship.On one site I show the past menus per calender week, on the other I want to show the order history of a specific user per calender week.I got the menu history working with the following query:public static function archives() { return Menu::selectRaw('week(date, 1) as kw, year(date) as year') ->orderByRaw('min(date) asc') ->groupBy('kw', 'year') ->get(); }Now i thought about the same query for the User, but I get errors ...
 laravel                     1 answers                     52 view
 2018-10-22         Berg

Eloquent - How to use "Has Many Through" relation?

I have three tables - products, features and product_feature - asproducts - id - namefeatures - id - keyproduct_feature - product_id - feature_id - valueI was retrieve all (key, value) pairs for a product. The SQL statement isSELECT key, value FROM productsJOIN product_feature pfON pf.product_id = "Product ID"JOIN features fON f.id = pf.feature_idHow do I established that relationship// Inside Product modelfunction features() { // Has many through relationship} This is a BelongsToMany relationship:public function features() { return $this->b...
 eloquent                     1 answers                     49 view
 2018-10-22         Jerome

Laravel Many to many relationship with custom key relation

Before you mark this question as duplicate, please see the details :) I have a problem related to many to many relationship with custom columns linkingI have following tables Employees -Id -brink_id <----- This is third party id I am saving of employee -nameJobs-id-brink_id <----- This is third party id I am saving of job-descriptionemployee_job-id-brink_id <----- This is third party id I am saving of relationship for third party-brink_employee_id-brink_job_idIn Employee Model I have created relationshippublic function jobs(){ return $this->belongsToMany('App...
 laravel                     1 answers                     53 view