Flutter: ListView disable scrolling with touchscreen
As mentioned in the comments, the NeverScrollableScrollPhysics class will do this:
NeverScrollableScrollPhysics class
Scroll physics that does not allow the user to scroll.
Disable ListView Scroll
I think the best way to do this is to use a SingleChildScrollView:
This widget is useful when you have a single box that will normally be
entirely visible, for example a clock face in a time picker, but you
need to make sure it can be scrolled if the container gets too small
in one axis (the scroll direction).
And instead of using a ListView
just use a Column
and place it inside of the SingleChildScrollView
:
SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[/**/],
),
)
Or if you need to use ListView
for some reason, you can use shrinkWrap
with NeverScrollableScrollPhysics
:
SingleChildScrollView(
child: ListView(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
children: <Widget>[/**/],
),
)
programmatically prevent scroll listview flutter
If you want to set it programatically, use a setState() to update the physics type like this:
ScrollPhysics physics = AlwaysScrollableScrollPhysics();
return Stack(
children: [
ListView(
physics: physics,
),
RaisedButton(
child: Text("Disable scrolling"),
onPressed: () {
setState((){
if(physics is AlwaysScrollableScrollPhysics){
physics = NeverScrollableScrollPhysics();
} else {
physics = AlwaysScrollableScrollPhysics();
}
});
},
),
]
);
Disable scrolling in listview
In your CustomListView:
@Override
public boolean dispatchTouchEvent(MotionEvent ev){
if(ev.getAction()==MotionEvent.ACTION_MOVE)
return true;
return super.dispatchTouchEvent(ev);
}
Then ListView will react to clicks, but will not change scroll position.
DIsable scrolling for listview and enable for whole layout
You can try this.
FOR xml PART DO THIS:
Put your entire layout data under one Scroll View, for example:
<ScrollView
android:id="@+id/scrollViewId"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> // SAY YOUR FIRST LIST VIEW:
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> // SAY YOUR SECONDLIST VIEW:
// Add your other views as per requirement....
</LinearLayout>
</ScrollView>
NOW IN JAVA CLASS DO THE FOLLOWING THING...
Just add this custom method to your code after setting adapter to list view:
setListViewHeightBasedOnChildren(listview)
For Example:
list = (ListView) findViewById(R.id.listview);
list.setAdapter(new ArrayAdapter<String>
(MainActivity.this,android.R.layout.simple_list_item_1,name));
setListViewHeightBasedOnChildren(list);
Do it same for second list view too.
Here is body of setListViewHeightBasedOnChildren METHOD
public static void setListViewHeightBasedOnChildren(ListView listView)
{
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null)
return;
int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED);
int totalHeight=0;
View view = null;
for (int i = 0; i < listAdapter.getCount(); i++)
{
view = listAdapter.getView(i, view, listView);
if (i == 0)
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth,
LayoutParams.MATCH_PARENT));
view.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + ((listView.getDividerHeight()) * (listAdapter.getCount()));
listView.setLayoutParams(params);
listView.requestLayout();
}
Hope it works for you.
ListView reaches end then stop scrolling and start scrolling the rest of the page Flutter
just set physics: ClampingScrollPhysics()
to the child ListView. It creates scroll physics that prevent the scroll offset from exceeding the bounds of the content. More about ListView and its physics refer to : https://medium.com/flutter-community/flutter-listview-and-scrollphysics-a-detailed-look-7f0912df2754
Related Topics
Android How to Display 2 Listviews in One Activity One After the Other
Android - Application (Apk) Maximum Size
Dynamic Form with Repeating Form
Use Tab with New Toolbar (Appcompat V7-21)
How to Fix "Unexpected Element <Queries> Found in <Manifest>" Error
How to Make a Vertical Seekbar in Android
How to Create Spinner-List Using Customadapter in Android
Font-Face on Android 4.0.X Doesn't Work
Android Canvas: Draw Transparent Circle on Image
Android Boot_Completed Not Received When Application Is Closed
Force Overflow Menu in Actionbarsherlock
Android: How to Overlay a Bitmap and Draw Over a Bitmap
Question Mark () in Xml Attributes for Android
How to Open Email Program via Intents (But Only an Email Program)
Version Conflict Updating to Play-Services 9.4.0 Android Studio 2.2