ListView inside scroll view magic

后端 未结 3 723
北海茫月
北海茫月 2021-01-21 03:32

For my app I want to enable a thing looking somehow like this:


    
        

        
相关标签:
3条回答
  • 2021-01-21 03:47

    in Layaout set Parameter

     <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true" >
    
          <ListView
                        android:id="@+id/listview"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
          </ListView>
    </ScrollView>
    

    And in the Coding Part Set the Dynamic height of listview according to device height

        LayoutParams lp = (LayoutParams) list1.getLayoutParams();
        int height = (arraylist.size()) * 80; 
    
            //arraylist list is in which all data is kept
    
        lp.height = height;
        listview.setLayoutParams(lp);
    
        listview.setAdapter(Adapter);
    
    0 讨论(0)
  • 2021-01-21 03:47
    *     ListView lv = (ListView)findViewById(R.id.myListView);  
          lv.setOnTouchListener(new ListView.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                switch (action) {
                case MotionEvent.ACTION_DOWN:
                    // Disallow ScrollView to intercept touch events.
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    break;
    
                case MotionEvent.ACTION_UP:
                    // Allow ScrollView to intercept touch events.
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
                }
    
                // Handle ListView touch events.
                v.onTouchEvent(event);
                return true;
            }
        });k;
                }
                // Handle ListView touch events.
                v.onTouchEvent(event);
                return true;
            }
        });*
    
    0 讨论(0)
  • 2021-01-21 03:48
        setOnScrollListener(new OnScrollListener() {
    
                @Override
                public void onScrollStateChanged(AbsListView view, int scrollState) {
                }
    
                @Override
                public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                    mFirstVisibleItem = firstVisibleItem;
                    mLastVisibleItem = firstVisibleItem + visibleItemCount;
                    mTotalOfItems = totalItemCount;
                }
    });
    

    I did it to know where I'm scrolling, using OnScrollListener and OnTouchListener to know to where I'll scroll, it works fine for me...

    setOnTouchListener(new OnTouchListener() {
    
            float oldY = -1;
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
    
                switch (event.getAction()) {
    
                case MotionEvent.ACTION_DOWN:
                    oldY = event.getY();
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    break;
    
                case MotionEvent.ACTION_UP:
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
                }
    
                if (oldY > -1 && 
                        (mFirstVisibleItem == 0 && oldY < event.getY()) || 
                        (mLastVisibleItem >= mTotalOfItems && oldY > event.getY())) {
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                }
    
                v.onTouchEvent(event);
    
                return true;
            }
        });
    
    0 讨论(0)
提交回复
热议问题