Android – how to change Recyclerview height dynamically?

I’m stuck with an issue about changing Recycler height based on its total items.
What I have tried is to use Layout Param like this:

        ViewGroup.LayoutParams params = myRecyclerView.getLayoutParams();
        params.height = itemHeight * numberOfItem;


  • Issue: Passing large data to second Activity
  • How to resume activity instead of restart when going “up” from action bar
  • Android API to check if call is Active or On Hold
  • How to start two animations at same time in android?
  • MPAndroidChart - Legend labels are being cut off
  • What is SharedPreferencesCompat? vs SharedPreferences
  •        ViewGroup.LayoutParams params = new  RecyclerView.LayoutParams(..WRAP_CONTENT, ...WRAP_CONTENT);;
           params.height = itemHeight * numberOfItem;

    But it didn’t work.
    How can I do it ? Please help me !

    Related posts:

    Benefits of switching from Eclipse to IntelliJ IDEA for Android development
    make a phone call click on a button
    Implementing Text Watcher for EditText
    CordovaResourceApi import unresolved phonegap
    SQLite Exception no such column when trying to select
    Authenticate user logged in with FB at my server using the Android Account Manager
  • string to charsequence
  • Android: Launch mode 'single instance'
  • Volley Not Parsing 404 response
  • Bad 'Patches' in 9-Patch File
  • android - “Exported receiver does not require permission” on receivers meant to receive from system services
  • AppCompat_v7 Toolbar as actionbar not showing 'always' actions from menu, but API Toolbar does
  • 3 Solutions collect form web for “Android – how to change Recyclerview height dynamically?”

    I tried this. It worked. May be help.

    public void onBindViewHolder(FeedListRowHolder feedListRowHolder, int i) {
        //this change height of rcv
         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
         params.height =80; //height recycleviewer
        FeedItem feedItem = feedItemList.get(i);
        feedListRowHolder.itemView.setActivated(selectedItems.get(i, false));
        feedListRowHolder.setClickListener(new FeedListRowHolder.ClickListener() {
            public void onClick(View v, int pos, boolean isLongClick) {
                if (isLongClick) {
                    // View v at position pos is long-clicked.
                    String poslx = pos + "";
                    Toast.makeText(mContext, "longclick " + poslx, Toast.LENGTH_SHORT).show();
                } else {
                    // View v at position pos is clicked.
                    String possx = pos + "";
                    Toast.makeText(mContext, "shortclick " + possx, Toast.LENGTH_SHORT).show();

    You should use LayoutParams of parent’s view in setLayoutParams(params).

    For example:


    Change LayoutParams in the code.

      RelativeLayout.LayoutParams lp =
                new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 500);

    This code works I am sure about it

    ViewGroup.LayoutParams params=recyclerview.getLayoutParams();

    The other thing you could do is make a linear layout as the parent of the recycler view and then increase the height dynamically for the parent view

    Consider the following XML below


    Consider the following code

    LinearLayout layout = (LinearLayout)findViewById(;
    LinearLayout.LayoutParams lp = (LayoutParams) layout.getLayoutParams();
    lp.height = 100;
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.