maxHeight does not work on RecyclerView

前端 未结 5 1544
情书的邮戳
情书的邮戳 2021-01-02 09:48

I\'ve a DialogFragment.

Layout:




        
5条回答
  •  孤独总比滥情好
    2021-01-02 10:04

    I had the same problem. I extended the RecyclerViewas follows:

    public class MaxHeightRecyclerView extends RecyclerView {
        private static final int MAX_HEIGHT = 765;
    
        public MaxHeightRecyclerView(Context context) {
            super(context);
        }
    
        public MaxHeightRecyclerView(Context context, @Nullable AttributeSet attrs) {
            super(context, attrs);
        }
    
        public MaxHeightRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        protected void onMeasure(int widthSpec, int heightSpec) {
            heightSpec = MeasureSpec.makeMeasureSpec((int) (MAX_HEIGHT / Resources.getSystem().getDisplayMetrics().density), MeasureSpec.AT_MOST);
            super.onMeasure(widthSpec, heightSpec);
        }
    }
    

提交回复
热议问题