There is a Fragment . There is a RecyclerView attached in the bottom. The bottom line is that the very first element is supposed to take up a little more space than the rest. I increase it in the ViewHolder the adapter itself when drawing as follows:

 public class myAdapter { ... @Override public void onBindViewHolder(final ViewHolder holder, final int position) { WeatherForDay weather = mWeathersList.get(position); holder.mDayTextView.setText(weather.getDay()); //todo update iconManager //need icon manager, with input -> String, output ->(R.drawable.icon) int holder.mIconImageView.setImageResource(R.drawable.testicon1); holder.mTempTextView.setText(weather.getTmp()); if (position == 0) { if (isFirstBind) { Log.d(DEBUG_TAG, "is first bind and first position"); holder.setBig(); isFirstBind = false; } } } ... public static class ViewHolder extends RecyclerView.ViewHolder { ... public void setBig() { LinearLayout.LayoutParams param = (LinearLayout.LayoutParams) mRoundLayout.getLayoutParams(); int newHeight = (int) (param.height * 1.2f); int newWidth = (int) (param.height * 1.2f); param.height = newHeight; param.width = newWidth; mRoundLayout.setLayoutParams(param); mRoundLayout.setBackgroundDrawable(createBigShape(newHeight)); } private Drawable createBigShape(int newHW) { GradientDrawable shape = new GradientDrawable(); shape.setShape(GradientDrawable.RECTANGLE); shape.setCornerRadii(new float[]{newHW, newHW, newHW, newHW, newHW, newHW, newHW, newHW}); shape.setColor(mContext.getResources().getColor(R.color.weryDark)); shape.setStroke(1, mContext.getResources().getColor(R.color.weryDark)); return shape; } ... } 

} How to make elements align not on the top edge, but on the bottom?

enter image description here

PS There is also a problem in that the Nth element is also somehow drawn by the "big" (on one device with a large screen N = 13, on a small screen N = 8)

PS2 Maybe there is some more optimal way to change any element RecyclerView ?

    2 answers 2

    You need to override the getItemViewType() method and for position = 0 display one type of markup, for other positions, another one.

    See this answer for implementation details.

    Additions from the comments about the repetition of large items in a certain number of positions:

    RecyclerView reuses items for optimization purposes (items that disappear from above appear below and only what is explicitly specified in onBindViewHolder() ) appear in them, and what is not explicitly installed when the item is binded is left from the past item.
    When you are banding, only position = 0 is processed, other positions are not defined, therefore, when it comes to the reuse of the first item (for example, in the 8th position), everything remains the same as it was (enlarged image), as for a position other than 0, it is not explicitly indicated which species to use, therefore, every Nth element is repeated.

    You can either force a state for each item by position (and not just for a large view) - large or small, but since you still have different types of items, it’s more logical to use an adapter tool specifically designed for this — override the getItemViewType() method - getItemViewType() overriding the adapter's getItemViewType() method, the adapter does not reuse items from different types among themselves, so this solution will also solve the problem of repeating a large view.

    • But how will this solution differ from what I used? I work with the same itemType, just changing its parameters under a certain condition. It also seems to me very strange that the logs contain the message Log.d (DEBUG_TAG, "is first bind and first position"); displayed once - and item'a two - abbath0767
    • Although I seem to be beginning to understand that the difference is still there. In English, this business is called header'om for recyclerview - abbath0767
    • @ abbath0767 RecyclerView reuses items for optimization (items that disappear from above appear below and only what is explicitly indicated in onBindViewHolder() ) changes in them, so every Nth element repeats itself. You can either force a state for each item - large or small, but since you still have different kinds of items, it’s more logical to use an adapter tool specifically designed for this. getItemViewType () is not only for the leader, but for any cases when different types of items are needed in one list, they can alternate. - pavlofff
    • @paviloff I may not understand correctly - but I have an item of one kind. Just one of them must change the size of some internal objects. But he still remains the same. Or are the same items with different LayoutParams already considered different? - abbath0767
    • one
      @ abbath0767 items are reused, something that is not explicitly installed when binding to the item remains from the past item. When you are banding, only position = 0 is processed, other positions are not defined, therefore, when it comes to the reuse of the first item (for example, in the 8th position), everything remains the same as it was (enlarged image), as for a position other than 0, it is not explicitly indicated which species to use. When overriding the adapter method getItemViewType() adapter does not reuse items from different types among themselves. - pavlofff Nov.

    Solved the problem with a crutch, in my opinion method. In xml added a fixed height size, which is equal to mRoundLayout * 1.2 (that is, that it would fit exactly with the increase) + another 20 dp for the stock under TextView and added bottom to android:gravity="center_horizontal|bottom" root element item.xml .

    The truth is why another element becomes "Big" I have not figured out