开发者

How to scroll ListView with in another scroll view

I have a problem;

I have a layout with scroll view over three list view A,B,C.

I want scroll hole layout as well as scroll each list view.

Problem:

List view are not scroll when layout is scroll if I remove s开发者_Python百科croll layout then list is scroll but layout is not scroll.

What is a possible solution?


Use the following method and enjoy!

    private void setListViewScrollable(final ListView list) {
    list.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            listViewTouchAction = event.getAction();
            if (listViewTouchAction == MotionEvent.ACTION_MOVE)
            {
                list.scrollBy(0, 1);
            }
            return false;
        }
    });
    list.setOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view,
                int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
            if (listViewTouchAction == MotionEvent.ACTION_MOVE)
            {
                list.scrollBy(0, -1);
            }
        }
    });
}

listViewTouchAction is a global integer value. If you can replace the line

list.scrollBy(0, 1);

with something else please share it with us.


We cant scroll listview within scrollview, because listview itself contains scroll option.

Check this link: http://code.google.com/p/android/issues/detail?id=6552

By that listview bug can do that list in scroll.


It depends on how you want the view and how you want the scrolling to be.

If you want all of them scrollable, then you should apply a fixed height on the list views. It will sometimes confuse which will scroll first.

Or you can populate the whole list with no scroll inside a scroll view, which will create a long list with all items from all of the lists.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜