Disable scrolling of a ListView contained within a ScrollView

I found a very simple solution for this. Just get the adapter of the listview and calculate its size when all items are shown. The advantage is that this solution also works inside a ScrollView. Example: public static void justifyListViewHeightBasedOnChildren (ListView listView) { ListAdapter adapter = listView.getAdapter(); if (adapter == null) { return; } ViewGroup … Read more

Scrollview inside constraint layout does not scroll to the bottom of the parent constraint

This layout works in my app. The trick is to set these two attributes in ScrollView: android:layout_height=”0dp” app:layout_constraintBottom_toBottomOf=”parent” The simplified layout from my app: <?xml version=”1.0″ encoding=”utf-8″?> <android.support.constraint.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:theme=”@style/ThemeOverlay.AppCompat.Light”> <RelativeLayout android:id=”@+id/linear” android:layout_width=”0dp” android:layout_height=”56dp” android:background=”@color/title” app:layout_constraintLeft_toLeftOf=”parent” app:layout_constraintRight_toRightOf=”parent” app:layout_constraintTop_toTopOf=”parent” /> <ScrollView android:layout_width=”0dp” android:layout_height=”0dp” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintLeft_toLeftOf=”parent” app:layout_constraintRight_toRightOf=”parent” app:layout_constraintTop_toBottomOf=”@id/linear”> <android.support.constraint.ConstraintLayout android:layout_width=”match_parent” android:layout_height=”wrap_content”> <TextView android:id=”@+id/titleView” … Read more

Stop ScrollView from auto-scrolling to an EditText

After struggling with that problem for quite some time, I’ve found a solution that seems to work without being too ugly. First, make sure that whatever ViewGroup (directly) contains your EditText has descendantFocusability set to “Before Descendants,” focusable set to “true” and focusableInTouchMode set to “true.” This will not be the ScrollView itself, but the … Read more

iOS ScrollView needs constraint for y position or height

Whenever using ScrollView with auto layout always follow below steps, ScrollView constraints: leadingSpace, topSpace, TrailingSpace, bottomSpace to superView and make sure when you control drag to add constraint, add it by pressing alt so that the constraint would be set without margin. Add UIView inside scroll view as container view and set its constraints: leadingSpace, … Read more

Scrolling EditText inside ScrollView

Try: @Override public void onCreate(Bundle savedInstanceState) { ….. EditText et = (EditText)findViewById(R.id.wo_task_comments); et.setOnTouchListener(this); ….. } @Override public boolean onTouch(View view, MotionEvent motionEvent) { if(view.getId() == R.id.wo_task_comments){ view.getParent().requestDisallowInterceptTouchEvent(true); switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_UP: view.getParent().requestDisallowInterceptTouchEvent(false); break; } } return false; } In your case: public class MyActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) … Read more

Webview in Scrollview

use: android:descendantFocusability=”blocksDescendants” on the wrapping layout this will prevent the WebView from jumping to its start. use: webView.clearView(); mNewsContent.requestLayout(); every time you change the WebView size to invalidate the layout, this will remove the empty spacing.

Scrolling with Multiple ListViews for Android

Forward touch event from touched view to other views. All your views will be synchronized expand/collapsed too. OnTouchListener mOnTouch = new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { MotionEvent newEvent = MotionEvent.obtain(event); switch(event.getAction()) { case MotionEvent.ACTION_MOVE: if(mTouched == null) { mTouched = v; } mMovingFlag = true; break; case MotionEvent.ACTION_UP: if(mMovingFlag==false) { … Read more

Can I scroll a ScrollView programmatically in Android?

The answer from Pragna does not work always, try this: mScrollView.post(new Runnable() { public void run() { mScrollView.scrollTo(0, mScrollView.getBottom()); } }); or mScrollView.post(new Runnable() { public void run() { mScrollView.fullScroll(mScrollView.FOCUS_DOWN); } }); if You want to scroll to start mScrollView.post(new Runnable() { public void run() { mScrollView.fullScroll(mScrollView.FOCUS_UP); } });