maxHeight does not work on RecyclerView

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

I\'ve a DialogFragment.

Layout:




        
5条回答
  •  有刺的猬
    2021-01-02 10:15

    You can achieve this using only XML as long as your parent layout is ConstraintLayout, which yours seems to be. Make these changes to your RecyclerView tag:

    Normally you only use a 0dp dimension when you constrain both sides of the view, but really all you have to do is provide enough constraints to define the view size (and constraining both sides is just the easiest way to do that). Once you have the height set to "match constraints", you can combine a default height constraint with a maximum height constraint to get exactly what you're looking for.

    Note you must be using a 1.1 version of the constraint layout library for this. Make sure your app's build.gradle file has something like:

    implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta5'
    

提交回复
热议问题