Android list view inside a scroll view

后端 未结 30 2086
一向
一向 2020-11-21 13:43

I have an android layout which has a scrollView with a number of elements with in it. At the bottom of the scrollView I have a listView

30条回答
  •  悲哀的现实
    2020-11-21 13:58

    This worked for me (link1, link2):

    • You Create Custom ListView Which is non Scrollable

      public class NonScrollListView extends ListView {
      
              public NonScrollListView(Context context) {
                  super(context);
              }
              public NonScrollListView(Context context, AttributeSet attrs) {
                  super(context, attrs);
              }
              public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
                  super(context, attrs, defStyle);
              }
              @Override
              public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                  int heightMeasureSpec_custom = View.MeasureSpec.makeMeasureSpec(
                          Integer.MAX_VALUE >> 2, View.MeasureSpec.AT_MOST);
                  super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
                  ViewGroup.LayoutParams params = getLayoutParams();
                  params.height = getMeasuredHeight();
              }
          }
      
    • In Your Layout File

      
      
          
      
              
      
              
              
      
              
      
                  
      
              
          
      
      
      
    • Create a object of your customListview instead of ListView like :

       NonScrollListView non_scroll_list = (NonScrollListView) findViewById(R.id.lv_nonscroll_list);
      

提交回复
热议问题