问题
In the app I am currently building I have been synchronizing ListViews with unbound Lists of data via BaseAdapter. This has been working so far but now I need to have a list of data inside a ScrollView. The problem with putting a ListView inside a ScrollView is that both views scroll and it make the activity difficult to navigate. From what I've read online the consensus seems to be that ListViews should never be put inside of scroll views for this reason, and that a LinearLayout or TableLayout should be used instead.
My quesion is this: Can any one tell me either how to get rid of the Scrolling Feature on a ListView or how to synchronize a List of data with a LinearLayout or a TableLayout through an adapter?
回答1:
You could make your own custom ListView component and then override the dispatchTouchEvent() method:
@Override
public boolean dispatchTouchEvent(MotionEvent event)
{
int action = event.getAction();
if (!scrollEnabled) {
event.setAction(MotionEvent.ACTION_CANCEL);
super.dispatchTouchEvent(event);
return true;
}
return super.dispatchTouchEvent(event);
}
In these kinds of situations though, what I've done in the past is have a separate vertical LinearLayout for my list and manually added TextViews via code to it, making it look similar to a listview.
来源:https://stackoverflow.com/questions/7772540/adapter-for-a-list-displayed-inside-a-scroll-view-non-scrolling-list-view