I have a RecyclerView in which I have an image, several TextView and 2 ImageButton s. I have 7-8 such lines to display in my Activity . Scrolling is very smooth in versions of Android 4.4.4 and below, but in a lollipop it gives a jitter effect. I think throwing speed control for the RecyclerView will help. I searched for this but found nothing. Instead, I found how to move my gaze to a specific throwing position.
But I want to control the speed of the throw. Can friction be used? And how to use friction.
menuRecyclerView = (RecyclerView) findViewById(R.id.menuList); menuRecyclerView.setHasFixedSize(true); LinearLayoutManager llm = new LinearLayoutManager(context); menuRecyclerView.setLayoutManager(llm); Scroller sc = new Scroller(context); sc.setFriction(ViewConfiguration.getScrollFriction() * 10);
This is my adapter for customizing the layout of the Rcycler view.
import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; import com.bumptech.glide.Glide; import news.circle.circle.R; public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.CustomViewHolder> { public RecyclerViewAdapter(Context context, List<MenuDescription> listOrder, DatabaseHandlerCart db , List<MenuDescription> vegList, List<MenuDescription> nonVegList, String menuTextData) { this.listOrder = listOrder; this.inflater = LayoutInflater.from(context); this.context = context; imageLoader = new ImageLoader(context); this.db = db; this.vegList = vegList; this.nonVegList = nonVegList; this.completeList = listOrder; this.menuTextData = menuTextData; } @Override public RecyclerViewAdapter.CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == TYPE_ITEM) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view, parent, false); return new CustomViewHolder(view, viewType); } else if (viewType == TYPE_HEADER) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.header, parent, false); return new CustomViewHolder(view, viewType); } return null; } @Override public void onBindViewHolder(final RecyclerViewAdapter.CustomViewHolder holder, int position) { if (holder.Holderid == 1) { final MenuDescription menu = listOrder.get(position - 1); holder.title.setText(menu.getName() + ""); holder.quant.setText(menu.getQuantity() + ""); holder.description.setText(menu.getDescription()); holder.title.setTypeface(Fonts.getFont(context, Constants.AVENIR_REGULAR)); holder.description.setTypeface(Fonts.getFont(context, Constants.AVENIR_REGULAR)); Glide.with(context).load(menu.getFlag_path()).placeholder(R.drawable.ic_order_now).fitCenter().into(holder.image); holder.inc.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
source share