Android list view inside a scroll view

后端 未结 30 2100
一向
一向 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 14:09

    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 = MeasureSpec.makeMeasureSpec(
                                Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
                        super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
                        ViewGroup.LayoutParams params = getLayoutParams();
                        params.height = getMeasuredHeight();    
                }
            }
    

    In Your Layout Resources File

         
            
    
                
    
                    
    
                    
                    
    
                    
    
                        
    
                    
                
    
            
    

    In Java File Create a object of your customListview instead of ListView like : NonScrollListView non_scroll_list = (NonScrollListView) findViewById(R.id.lv_nonscroll_list);

提交回复
热议问题