How to set RecyclerView Max Height

ConstraintLayout offers maximum height for its children. <android.support.constraint.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:layout_width=”match_parent” android:layout_height=”match_parent”> <ListView android:layout_width=”0dp” android:layout_height=”wrap_content” android:scrollbars=”vertical” app:layout_constrainedHeight=”true” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintHeight_max=”300dp” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” /> </android.support.constraint.ConstraintLayout>

Recyclerview not call any Adapter method :onCreateViewHolder,onBindViewHolder,

Other than @SanatiSharif’s and @sohrab’s answer, you have to follow below mandatory step. Make sure you call setLayoutManager, something like below. recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); before setting adapter into recyclerView, otherwise it is not going to work. You can customize it if you need. this link will give you some idea of how LayoutManager works.

GridLayoutManager – how to auto fit columns?

You can calculate available number of columns, given a desired column width, and load the image as calculated. Define a static funtion to calculate as: public class Utility { public static int calculateNoOfColumns(Context context, float columnWidthDp) { // For example columnWidthdp=180 DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); float screenWidthDp = displayMetrics.widthPixels / displayMetrics.density; int noOfColumns = (int) … Read more

Scroll to top in RecyclerView with LinearLayoutManager

Continuing from above comments, ideally, replacing mRecyclerView.smoothScrollToPosition(0); in the onClick of the floating action button with mLayoutManager.scrollToPositionWithOffset(0, 0); should work. You can also remove the SnackBar code, because you don’t need it anyways. So, all in all your above method should look like public void setFloatingActionButton(final View view) { float actionButton = (android.support.design.widget.FloatingActionButton) getActivity() .findViewById(R.id.float); … Read more

RecyclerView remove divider / decorator after the last item

Try this Code, it won’t show divider for the last item. This method will give you more control over drawing divider. public class DividerItemDecorator extends RecyclerView.ItemDecoration { private Drawable mDivider; public DividerItemDecorator(Drawable divider) { mDivider = divider; } @Override public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) { int dividerLeft = parent.getPaddingLeft(); int dividerRight = … Read more

Is there any way to Show Google Admob in Android Recycler View

Here is complete example. I just created an example app for you. Main Activity import android.content.Context; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import java.util.ArrayList; import java.util.List; public class Main extends AppCompatActivity { public static final String TAG = Main.class.getSimpleName(); private Context mContext; private List<MyListModel> mList; private RecyclerView mRecyclerView; private RecyclerView.Adapter mAdapter; … Read more

Start new Activity with onClick() in RecyclerView

I found the solution!:) There’s this way of handling item click in Recyclerview with itemView given within the ViewHolder class: public static class ViewHolder extends RecyclerView.ViewHolder { public ViewHolder(LayoutInflater inflater, ViewGroup parent) { super(inflater.inflate(R.layout.fragment_channel, parent, false)); itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Context context = v.getContext(); Intent intent = new Intent(context, ChannelDetailActivity.class); … Read more

How to scroll recyclerView programmatically?

You can use scrollToPosition() recyclerView.post(new Runnable() { @Override public void run() { recyclerView.scrollToPosition(adapter.getItemCount() – 1); // Here adapter.getItemCount()== child count } }); or smoothScrollToPosition() recyclerView.post(new Runnable() { @Override public void run() { recyclerView.smoothScrollToPosition(adapter.getItemCount()- 1); } }); To move up again, you need to call the above method with index 0. But first, you need to … Read more