Android ScrollView set height for displayed content

后端 未结 4 1573
我寻月下人不归
我寻月下人不归 2021-02-19 07:56

I\'m having a lot of trouble trying solve the issue of having a static height scrollable area within a layout. I have three long lists that need to be displayed on the same scre

4条回答
  •  别那么骄傲
    2021-02-19 08:52

    My simple solution.
    Set ScrollView heigh in xml:

    android:layout_height="wrap_content"
    

    Add this code to set Max Height to 200 if current measured Height is > 200

    sv.measure(0, 0);
    if (nsv.getMeasuredHeight() > 200) {
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                                          ViewGroup.LayoutParams.MATCH_PARENT, 200);
            sv.setLayoutParams(lp);
    }
    

    ScrollView in my example is into LinearLayout, so I used LinearLayout.LayoutParams.

提交回复
热议问题