ListView dentro de ScrollView no se desplaza en Android


Estoy teniendo problemas con un desplazamiento ListView dentro de un ScrollView. Tengo una Actividad que tiene algunos EditTexts en la parte superior y luego un host de pestañas con dos pestañas que tienen una vista de lista cada una. Cuando las vistas EditText están enfocadas, aparece el teclado de software y como tengo una vista de desplazamiento, el contenido se puede desplazar. Pero el problema viene cuando hay más elementos en ListViews (unos en pestañas), no soy capaz de desplazarse por la vista de lista, incluso si hay más elementos.

El siguiente es el diseño XML:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="?backgroundImage"
    android:orientation="vertical">

  <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:layout_alignParentBottom="true"
        android:layout_margin="10dip"
        android:id="@+id/buttons">
    <Button
            android:text="Save"
            android:layout_margin="2dip"
            android:textSize="20dip"
            android:id="@+id/btnSaveorUpdate"
            android:layout_height="wrap_content"
            android:layout_width="145dip"></Button>
    <Button
            android:text="Cancel"
            android:layout_margin="2dip"
            android:textSize="20dip"
            android:id="@+id/btnCancelorDelete"
            android:layout_height="wrap_content"
            android:layout_width="145dip"></Button>
  </LinearLayout>
  <ScrollView
        android:layout_above="@id/buttons"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:layout_margin="10dip">
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="10dip">
      <TextView
                android:text="Bill details"
                android:textColor="?textColorDark"
                android:layout_alignParentTop="true"
                android:id="@+id/txtEnterDetails"
                android:textSize="25dip"
                android:textStyle="bold"
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:layout_marginBottom="2dip"></TextView>
      <LinearLayout
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:layout_width="0dip"
                android:layout_height="0dip" />
      <EditText
                android:layout_width="fill_parent"
                android:hint="Enter data"
                android:inputType="numberDecimal"
                android:id="@+id/txtSample"
                android:textSize="@dimen/editText"
                android:layout_height="@dimen/editTextHeight"
                android:text=""></EditText>
      <EditText
                android:layout_width="fill_parent"
                android:id="@+id/txtDescription"
                android:hint="Enter description"
                android:textSize="@dimen/editText"
                android:layout_height="@dimen/editTextHeight"
                android:inputType="text"
                android:text=""></EditText>
      <EditText
                android:layout_width="fill_parent"
                android:id="@+id/txtComment"
                android:hint="Enter comment (if any)"
                android:textSize="@dimen/editText"
                android:layout_height="@dimen/editTextHeight"
                android:inputType="text"
                android:text=""></EditText>
      <LinearLayout
                android:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
        <TextView
                    android:id="@+id/txtDate"
                    android:layout_width="wrap_content"
                    android:text=""
                    android:textSize="20dip"
                    android:textColor="?textColorDark"
                    android:layout_marginLeft="10dip"
                    android:layout_height="@dimen/editTextHeight"
                    android:layout_gravity="center_vertical" />
        <Button
                    android:id="@+id/btnPickDate"
                    android:layout_width="wrap_content"
                    android:layout_height="@dimen/editTextHeight"
                    android:text="Select date"
                    android:layout_margin="2dip"
                    android:textSize="15dip"
                    android:layout_gravity="center_vertical" />
      </LinearLayout>
      <TabHost
                android:id="@+id/tabhost"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
        <LinearLayout
                    android:id="@+id/linearLayout1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical">
          <TabWidget
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:id="@android:id/tabs"></TabWidget>
          <FrameLayout
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:id="@android:id/tabcontent">
            <ScrollView
                            android:layout_above="@id/buttons"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:fillViewport="true"
                            android:id="@+id/tab1">
              <LinearLayout
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:orientation="vertical">
                <TableLayout
                                    android:layout_height="wrap_content"
                                    android:layout_width="fill_parent">
                  <TableRow
                                        android:id="@+id/tableRow1"
                                        android:layout_marginLeft="2dip"
                                        android:layout_marginRight="5dip"
                                        android:layout_width="fill_parent"
                                        android:layout_height="wrap_content">
                    <LinearLayout
                                            android:layout_width="fill_parent"
                                            android:layout_height="wrap_content"
                                            android:orientation="horizontal">
                      <ImageView
                                                android:src="@drawable/ic_menu_invite"
                                                android:layout_width="40dip"
                                                android:layout_height="40dip"
                                                android:layout_gravity="center_vertical"></ImageView>
                      <TextView
                                                android:text="Add friend"
                                                android:layout_height="wrap_content"
                                                android:layout_width="fill_parent"
                                                android:layout_centerVertical="true"
                                                android:textColor="?textColorDark"
                                                android:textSize="@dimen/editText"
                                                android:layout_gravity="center_vertical" />
                    </LinearLayout>
                  </TableRow>
                  <TableRow
                                        android:layout_width="fill_parent"
                                        android:layout_height="wrap_content"
                                        android:layout_marginLeft="5dip"
                                        android:layout_marginRight="5dip">
                    <TextView
                                            android:id="@+id/txtData1"
                                            android:layout_width="170dip"
                                            android:layout_height="wrap_content"
                                            android:text="Data"
                                            android:textSize="14dip"
                                            android:textStyle="bold"
                                            android:textColor="#000000">
                    </TextView>
                    <TextView
                                            android:id="@+id/txtData2"
                                            android:layout_width="wrap_content"
                                            android:layout_height="wrap_content"
                                            android:text="Sample"
                                            android:textSize="13dip"
                                            android:textColor="#000000"></TextView>

                  </TableRow>
                </TableLayout>
                <ListView
                                    android:cacheColorHint="#00000000"
                                    android:id="@+id/ListView01"
                                    android:layout_height="wrap_content"
                                    android:layout_width="fill_parent" />
              </LinearLayout>
            </ScrollView>
            <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:gravity="center_horizontal"
                            android:id="@+id/tab2"
                            android:orientation="vertical">
              <TableLayout
                                android:layout_height="wrap_content"
                                android:layout_width="fill_parent">
                <TableRow
                                    android:id="@+id/tableRow2"
                                    android:layout_marginLeft="2dip"
                                    android:layout_marginRight="5dip"
                                    android:layout_width="fill_parent"
                                    android:layout_height="wrap_content">
                  <LinearLayout
                                        android:layout_width="fill_parent"
                                        android:layout_height="wrap_content"
                                        android:orientation="horizontal">
                    <ImageView
                                            android:src="@drawable/ic_menu_invite"
                                            android:layout_width="40dip"
                                            android:layout_height="40dip"
                                            android:layout_gravity="center_vertical"></ImageView>
                    <TextView
                                            android:text="Sample"
                                            android:layout_height="wrap_content"
                                            android:layout_width="fill_parent"
                                            android:layout_centerVertical="true"
                                            android:textColor="?textColorDark"
                                            android:textSize="@dimen/editText"
                                            android:layout_gravity="center_vertical" />
                  </LinearLayout>
                </TableRow>
                <TableRow
                                    android:layout_width="fill_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_marginLeft="5dip"
                                    android:layout_marginRight="5dip">
                  <TextView
                                        android:id="@+id/txtUser1"
                                        android:layout_width="170dip"
                                        android:layout_height="wrap_content"
                                        android:text="User"
                                        android:textSize="14dip"
                                        android:textStyle="bold"
                                        android:textColor="#000000">
                  </TextView>
                  <TextView
                                        android:id="@+id/txtUserData"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="UserData"
                                        android:textSize="13dip"
                                        android:textColor="#000000"></TextView>
                </TableRow>
              </TableLayout>

              <ListView
                                android:cacheColorHint="#00000000"
                                android:id="@+id/ListView02"
                                android:layout_height="wrap_content"
                                android:layout_width="fill_parent" />

            </LinearLayout>


          </FrameLayout>
        </LinearLayout>
      </TabHost>
    </LinearLayout>
  </ScrollView>
</RelativeLayout>

Por favor, ¿alguien puede decirme cuál es el problema aquí? Tengo otro post en el ListView dentro del problema ScrollView, pero no fueron de utilidad en mi caso.

Author: tcooc, 2011-06-02

26 answers

No debe poner un ListView dentro de un ScrollView porque la clase ListView implementa su propio desplazamiento y simplemente no recibe gestos porque todos son manejados por el padre ScrollView. Le recomiendo encarecidamente que simplifique su diseño de alguna manera. Por ejemplo, puede agregar vistas que desee desplazar a ListView como encabezados o pies de página.

ACTUALIZACIÓN :

A partir del nivel de API 21 (Lollipop), los contenedores de desplazamiento anidados son compatibles oficialmente con Android SDK. Hay un montón de métodos en las clases View y ViewGroup que proporcionan esta funcionalidad. Para hacer que el desplazamiento anidado funcione en el Lollipop, debe habilitarlo para una vista de desplazamiento hijo agregando android:nestedScrollingEnabled="true" a su declaración XML o llamando explícitamente a setNestedScrollingEnabled(true).

Si desea hacer que el desplazamiento anidado funcione en dispositivos pre-Lollipop, lo que probablemente haga, debe usar las clases de utilidad correspondientes de la biblioteca de Soporte. Primero tienes que reemplazarte ScrollView con NestedScrollView. Este último implementa NestedScrollingParenty NestedScrollingChild para que pueda ser utilizado como un contenedor de desplazamiento padre o hijo.

Pero ListView no admite el desplazamiento anidado, por lo tanto, debe subclasarlo e implementar NestedScrollingChild. Afortunadamente, la biblioteca de Soporte proporciona la clase NestedScrollingChildHelper, por lo que solo tiene que crear una instancia de esta clase y llamar a sus métodos desde los métodos correspondientes de su clase view.

 147
Author: Michael,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-24 08:56:06

Encontré una solución que funciona de manera excelente y puede desplazarse por el ListView sin problemas:

ListView lv = (ListView)findViewById(R.id.myListView);  // your listview inside scrollview
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;
        }
    });

Lo que esto hace es desactivar los TouchEvent s en el ScrollView y hacer que el ListView interceptarlos. Es simple y funciona todo el tiempo.

 291
Author: Moisés Olmedo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-16 16:22:48

También tengo una solución. Siempre uso este método. Prueba esto

<ScrollView
    android:id="@+id/createdrill_scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="15dp" >

            <net.thepaksoft.fdtrainer.NestedListView
                android:id="@+id/crewList"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_weight="1"
                android:background="@drawable/round_shape"
                android:cacheColorHint="#00000000" >
            </net.thepaksoft.fdtrainer.NestedListView>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="15dp" >

            <net.thepaksoft.fdtrainer.NestedListView
                android:id="@+id/benchmarksList"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_weight="1"
                android:background="@drawable/round_shape"
                android:cacheColorHint="#00000000" >
            </net.thepaksoft.fdtrainer.NestedListView>
        </LinearLayout>

</ScrollView>

NestedListView.clase java:

public class NestedListView extends ListView implements OnTouchListener, OnScrollListener {

    private int listViewTouchAction;
    private static final int MAXIMUM_LIST_ITEMS_VIEWABLE = 99;

    public NestedListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        listViewTouchAction = -1;
        setOnScrollListener(this);
        setOnTouchListener(this);
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
            int visibleItemCount, int totalItemCount) {
        if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) {
            if (listViewTouchAction == MotionEvent.ACTION_MOVE) {
                scrollBy(0, -1);
            }
        }
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int newHeight = 0;
        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        if (heightMode != MeasureSpec.EXACTLY) {
            ListAdapter listAdapter = getAdapter();
            if (listAdapter != null && !listAdapter.isEmpty()) {
                int listPosition = 0;
                for (listPosition = 0; listPosition < listAdapter.getCount()
                        && listPosition < MAXIMUM_LIST_ITEMS_VIEWABLE; listPosition++) {
                    View listItem = listAdapter.getView(listPosition, null, this);
                    //now it will not throw a NPE if listItem is a ViewGroup instance
                    if (listItem instanceof ViewGroup) {
                        listItem.setLayoutParams(new LayoutParams(
                                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                    }
                    listItem.measure(widthMeasureSpec, heightMeasureSpec);
                    newHeight += listItem.getMeasuredHeight();
                }
                newHeight += getDividerHeight() * listPosition;
            }
            if ((heightMode == MeasureSpec.AT_MOST) && (newHeight > heightSize)) {
                if (newHeight > heightSize) {
                    newHeight = heightSize;
                }
            }
        } else {
            newHeight = getMeasuredHeight();
        }
        setMeasuredDimension(getMeasuredWidth(), newHeight);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) {
            if (listViewTouchAction == MotionEvent.ACTION_MOVE) {
                scrollBy(0, 1);
            }
        }
        return false;
    }
}
 135
Author: Muhammad Aamir Ali,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-06 14:21:53

Tienes Que reemplazar tu <ScrollView ></ScrollView> con este Custom ScrollView como <com.tmd.utils.VerticalScrollview > </com.tmd.utils.VerticalScrollview >

package com.tmd.utils;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ScrollView;

public class VerticalScrollview extends ScrollView{

    public VerticalScrollview(Context context) {
        super(context);
    }

     public VerticalScrollview(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public VerticalScrollview(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        final int action = ev.getAction();
        switch (action)
        {
            case MotionEvent.ACTION_DOWN:
                    Log.i("VerticalScrollview", "onInterceptTouchEvent: DOWN super false" );
                    super.onTouchEvent(ev);
                    break;

            case MotionEvent.ACTION_MOVE:
                    return false; // redirect MotionEvents to ourself

            case MotionEvent.ACTION_CANCEL:
                    Log.i("VerticalScrollview", "onInterceptTouchEvent: CANCEL super false" );
                    super.onTouchEvent(ev);
                    break;

            case MotionEvent.ACTION_UP:
                    Log.i("VerticalScrollview", "onInterceptTouchEvent: UP super false" );
                    return false;

            default: Log.i("VerticalScrollview", "onInterceptTouchEvent: " + action ); break;
        }

        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        super.onTouchEvent(ev);
        Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() );
         return true;
    }
}
 46
Author: Atul Bhardwaj,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-26 13:30:23

Tuve el mismo problema y mientras buscaba en Google encontré tu pregunta. Si respuesta marcada funcionó para mí también, pero hubo algún problema.
De todos modos encontré otra solución. que funciona perfectamente sin hacer malabarismo.

 11
Author: Priyank,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-13 06:11:30
list.setOnTouchListener(new OnTouchListener() {
    // Setting on Touch Listener for handling the touch inside ScrollView
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // Disallow the touch request for parent scroll on touch of child view
        v.getParent().requestDisallowInterceptTouchEvent(true);
        return false;
    }
});
 10
Author: Salman Ashraf,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-01 18:52:54

Aquí está el método exacto de usar Listview con en Scrollview. Todo lo que tenemos para manejar eventos táctiles.

      lstvNextTracks.setOnTouchListener(new OnTouchListener()
      {
          @Override
          public boolean onTouch(View v, MotionEvent event)
          {
         Log.e("Lisview *************", "focused");
         SCView.requestDisallowInterceptTouchEvent(true);
         return false;
          }
      });




    SCView.setOnTouchListener(new OnTouchListener()
    {

        @Override
        public boolean onTouch(View v, MotionEvent event)
        {
            int arr[] = new int[] { 1, 2 };
            lstvNextTracks.getLocationOnScreen(arr);

            /* Get bounds of child Listview*/
            int lstvTop = arr[0];
            int lstvBottom = arr[1] + lstvNextTracks.getHeight();
            int lstvLeft = arr[1];
            int lstvRight = arr[0] + lstvNextTracks.getWidth();

            float x = event.getRawX();
            float y = event.getRawY();

            if (event.getAction() == MotionEvent.ACTION_DOWN)
            {
                /*check if child ListView bounds are touched*/
                if (x > lstvTop && x < lstvBottom && y > lstvLeft && y < lstvRight)
                {
                    SCView.clearFocus();
                    /*This statement tells the ScrollView to do not handle this touch event, so the child Listview will handle this touch event and will scroll */
                    SCView.requestDisallowInterceptTouchEvent(true);
                    /*The child Listview isFocusable attribute must be set to true otherwise it will not work*/
                    lstvNextTracks.requestFocus();
                    return true;
                } else
                    return false;
            } else if (event.getAction() == MotionEvent.ACTION_MOVE)
            {

                if (x > lstvTop && x < lstvBottom && y > lstvLeft && y < lstvRight)
                {
                    SCView.clearFocus();
                    SCView.requestDisallowInterceptTouchEvent(true);
                    lstvNextTracks.requestFocus();
                    return true;
                } else
                    return false;
            } else if (event.getAction() == MotionEvent.ACTION_UP)
            {
                SCView.clearFocus();
                SCView.requestDisallowInterceptTouchEvent(true);
                lstvNextTracks.requestFocus();
                return false;
            } else
            {
                return false;
            }
        }
    });
 6
Author: Muhammad Bilal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-04-04 08:41:55

Utilice el siguiente método y disfrutar!

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 es un valor entero global. Si puede reemplazar la línea

list.scrollBy(0, 1);

Con algo más, por favor compártalo con nosotros.

Disfrute!

 6
Author: Bobs,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-01 18:42:55

Es una mala práctica tener dos vistas de desplazamiento diferentes juntas. ListView tiene su propia funcionalidad de desplazamiento y la altura se ajusta automáticamente de acuerdo con la configuración del adaptador para sus elementos de fila (Keelping en mente, no estamos estableciendo una altura específica para ListView en nuestro xml de diseño). Sin embargo, en su caso, puede reemplazar ListView con una clase y esto ajustará la altura de su ListView teniendo en cuenta que su ListView está dentro de ScrollView.

Esto ayudará usted:

public class ExpandableHeightListview extends ListView
{

    boolean expanded = false;

    public ExpandableHeightListview(Context context)
    {
        super(context);
    }

    public ExpandableHeightListview(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public ExpandableHeightListview(Context context, AttributeSet attrs,int defStyle)
    {
        super(context, attrs, defStyle);
    }

    public boolean isExpanded()
    {
        return expanded;
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        // HACK! TAKE THAT ANDROID!
        if (isExpanded())
        {
            // Calculate entire height by providing a very large height hint.
            // But do not use the highest 2 bits of this integer; those are
            // reserved for the MeasureSpec mode.
            int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, expandSpec);

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = getMeasuredHeight();
        }
        else
        {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

    public void setExpanded(boolean expanded)
    {
        this.expanded = expanded;
    }
}

Ahora extienda su ListView con esta clase, simplemente cambie su etiqueta ListView de su xml de recurso a fumar de esta manera,

<yourpackagename.ExpandableHeightListview
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/White"
            android:scrollbars="none"
            android:orientation="vertical"
            android:fadingEdge="none">
            </cyourpackagename.ExpandableHeightListview>

Esto resolverá su problema de desplazamiento de ListView, ya que ahora el desplazamiento padre es administrado por ScrollView en lugar de ListView.

 4
Author: Ravi Kabra,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-29 07:19:40

Tengo un problema similar y resuelto creando una clase personalizada extendiendo con ListView.

ScrollableListView.java

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

public class ScrollableListView extends ListView {

    public ScrollableListView (Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ScrollableListView (Context context) {
        super(context);
    }

    public ScrollableListView (Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

Uso:

<com.my.package.ScrollableListView
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
 2
Author: Waqar UlHaq,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-04 08:08:32

Demo_ListView_In_ScrollView

==============================

            package com.app.custom_seekbar;

            import java.util.ArrayList;

            import android.app.Activity;
            import android.os.Bundle;
            import android.widget.ListView;

            public class Demo_ListView_In_ScrollView  extends Activity
            {
                ListView listview;
                ArrayList<String> data=null;
                listview_adapter adapter=null;

                @Override
                protected void onCreate(Bundle savedInstanceState) 
                {
                    // TODO Auto-generated method stub
                    super.onCreate(savedInstanceState);
                    super.setContentView(R.layout.demo_listview_in_scrollview_activity);
                    init();
                    set_data();
                    set_adapter();


                }
                public void init()
                {
                    listview=(ListView)findViewById(R.id.listView1);
                    data=new ArrayList<String>();

                }
                public void set_data()
                {
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");
                    data.add("Meet");
                    data.add("prachi");
                    data.add("shailesh");
                    data.add("manoj");
                    data.add("sandip");
                    data.add("zala");
                    data.add("tushar");



                }

                public void set_adapter()
                {
                    adapter=new listview_adapter(Demo_ListView_In_ScrollView.this,data);
                    listview.setAdapter(adapter);
                    Helper.getListViewSize(listview); // set height of listview according to Arraylist item  
                }

            }

========================

Listview_adapter

==========================

        package com.app.custom_seekbar;

        import java.util.ArrayList;

        import android.app.Activity;
        import android.view.LayoutInflater;
        import android.view.MotionEvent;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.ArrayAdapter;
        import android.widget.LinearLayout;
        import android.widget.ScrollView;
        import android.widget.TextView;

        public class listview_adapter  extends ArrayAdapter<String>  
        {
            private final Activity context;
            ArrayList<String>data;
            class ViewHolder 
            {
                public TextView tv_name;
                public ScrollView scroll;
                public LinearLayout l1;
            }


            public listview_adapter(Activity context, ArrayList<String> all_data) {
                super(context, R.layout.item_list_xml, all_data);
                this.context = context;
                data=all_data;
            }
            @Override
            public View getView(final int position, View convertView, ViewGroup parent) {
                View rowView = convertView;
                ViewHolder viewHolder;
                if (rowView == null)
                {
                    LayoutInflater inflater = context.getLayoutInflater();
                    rowView = inflater.inflate(R.layout.item_list_xml, null);

                    viewHolder = new ViewHolder();

                    viewHolder.tv_name=(TextView)rowView.findViewById(R.id.textView1);

                    rowView.setTag(viewHolder);
                }
                else
                viewHolder = (ViewHolder) rowView.getTag();

                viewHolder.tv_name.setText(data.get(position).toString());
                return rowView;

            }


        }

===================================

Clase Auxiliar

====================================

    import android.util.Log;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ListAdapter;
    import android.widget.ListView;

    public class Helper {
        public static void getListViewSize(ListView myListView) {
            ListAdapter myListAdapter = myListView.getAdapter();
            if (myListAdapter == null) {
                //do nothing return null
                return;
            }
            //set listAdapter in loop for getting final size
            int totalHeight = 0;
            for (int size = 0; size < myListAdapter.getCount(); size++) {
                View listItem = myListAdapter.getView(size, null, myListView);
                listItem.measure(0, 0);
                totalHeight += listItem.getMeasuredHeight();
            }
          //setting listview item in adapter
            ViewGroup.LayoutParams params = myListView.getLayoutParams();
            params.height = totalHeight + (myListView.getDividerHeight() *                   (myListAdapter.getCount() - 1));
            myListView.setLayoutParams(params);
            // print height of adapter on log
            Log.i("height of listItem:", String.valueOf(totalHeight));
        }
    }

========================

Demo_listview_in_scrollview_activity.xml

========================

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <ScrollView
                android:id="@+id/scrollView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >

                    <ListView
                        android:id="@+id/listView1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" >
                    </ListView>
                </LinearLayout>
            </ScrollView>

        </LinearLayout>

================

Item_list_xml.xml

==================

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:gravity="center"
                android:text="TextView"
                android:textSize="14sp" />

        </LinearLayout>
 1
Author: shailesh Rohit,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-22 09:10:35

La mejor solución es usar NestedScrollVew con RecyclerView o si desea ir con Listview, puede agregar la vista de encabezado y pie de página a esto. Por ejemplo:

View footerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.outofoffice_footer_view, null, false);
infoListView.addFooterView(footerView);
 1
Author: Srishti Roy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-08 07:56:19

He probado y probado casi todos los métodos mencionados anteriormente, confía en mí, después de huir completamente de RecyclerView, reemplazé mi ListView con RecyclerView y funcionó perfectamente. No necesitaba ninguna biblioteca de terceros para ExtendedHeightListView y todo, simplemente RecyclerView simple y simple.

Así que aquí está mi archivo de diseño antes de RecyclerView:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="5dp">

<RelativeLayout
    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:id="@+id/relativeLayoutre"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"
    tools:context="com.example.android.udamovappv3.activities.DetailedActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar_detail"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_gravity="top"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <TextView
        android:id="@+id/title_name"
        android:layout_width="fill_parent"
        android:layout_height="128dp"
        android:layout_alignParentStart="true"
        android:layout_marginTop="59dp"
        android:background="#079ED9"
        android:gravity="left|center"
        android:padding="25dp"
        android:text="Name"
        android:textColor="#ffffff"
        android:textSize="30sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/my_toolbar_detail"
        app:layout_constraintVertical_bias="0.0"
        tools:layout_editor_absoluteX="0dp" />


    <ImageView
        android:id="@+id/iv_poster"
        android:layout_width="131dp"
        android:layout_height="163dp"
        android:layout_alignStart="@+id/my_toolbar_detail"
        android:layout_below="@+id/title_name"
        android:layout_marginBottom="15dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="15dp"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:srcCompat="@mipmap/ic_launcher" />

    <Button
        android:id="@+id/bt_mark_as_fav"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/iv_poster"
        android:layout_alignParentEnd="true"
        android:layout_marginBottom="11dp"
        android:layout_marginEnd="50dp"
        android:background="#079ED9"
        android:text="Mark As \n Favorite"
        android:textSize="10dp" />

    <TextView
        android:id="@+id/tv_runTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/tv_rating"
        android:layout_below="@+id/tv_releaseDate"
        android:layout_marginTop="11dp"
        android:text="TextView"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/tv_releaseDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/tv_runTime"
        android:layout_alignTop="@+id/iv_poster"
        android:text="TextView"
        android:textSize="25dp" />

    <TextView
        android:id="@+id/tv_rating"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/bt_mark_as_fav"
        android:layout_below="@+id/tv_runTime"
        android:layout_marginTop="11dp"
        android:text="TextView" />

    <TextView
        android:id="@+id/tv_overview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/iv_poster"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="5dp"
        android:foregroundGravity="center"
        android:text="adasdasdfadfsasdfasdfasdfasdfnb agfjuanfalsbdfjbdfklbdnfkjasbnf;kasbdnf;kbdfas;kdjabnf;lbdnfo;aidsnfl';asdfj'plasdfj'pdaskjf'asfj'p[asdfk"
        android:textColor="#000000"
         />


    <RelativeLayout
        android:id="@+id/foodItemActvity_linearLayout_fragments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_below="@+id/tv_overview">
        <TextView
            android:id="@+id/fragment_dds_review_textView_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Reviews:"

            android:textAppearance="?android:attr/textAppearanceMedium" />
        <com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView
            android:id="@+id/expandable_listview"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/fragment_dds_review_textView_label"
            android:padding="8dp">

        </com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView>
    </RelativeLayout>
</RelativeLayout>
</ScrollView>

ESTO ES DESPUÉS DE REEMPLAZAR MI LISTVIEW CON UNA DE LAS MUCHAS SOLUCIONES MENCIONADAS ANTERIORMENTE. Así que el problema era que el listview no se comportaba correctamente debido a 2 error scrollview (tal vez no un error) en Android.

He sustituido el con la vista recycler para formar mi diseño final.

Este es mi adaptador de vista recycler:

public class TrailerAdapter extends RecyclerView.Adapter<TrailerAdapter.TrailerAdapterViewHolder> {

private ArrayList<String> Youtube_URLS;

private Context Context;

public TrailerAdapter(Context context, ArrayList<String> Youtube_URLS){
    this.Context = context;
    this.Youtube_URLS = Youtube_URLS;
}
@Override
public TrailerAdapter.TrailerAdapterViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.trailer_layout, parent, false);
    return new TrailerAdapterViewHolder(view);
}

@Override
public void onBindViewHolder(TrailerAdapter.TrailerAdapterViewHolder holder, int position) {
    Picasso.with(Context).load(R.drawable.ic_play_arrow_black_24dp).into(holder.iv_playbutton);
    holder.item_id.setText(Youtube_URLS.get(position));
}

@Override
public int getItemCount() {
    if(Youtube_URLS.size()==0){
        return 0;
    }else{
        return Youtube_URLS.size();
    }
}

public class TrailerAdapterViewHolder extends RecyclerView.ViewHolder {
    ImageView iv_playbutton;
    TextView item_id;

    public TrailerAdapterViewHolder(View itemView) {
        super(itemView);
        iv_playbutton = (ImageView)itemView.findViewById(R.id.play_button);
        item_id = (TextView)itemView.findViewById(R.id.tv_trailer_sequence);
    }
}
}

Y este es mi diseño personalizado RecyclerView:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="56dp"
    android:padding="6dip" >

    <ImageView
        android:id="@+id/play_button"
        android:layout_width="70dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="6dip"
        android:layout_marginStart="12dp"
        android:src="@drawable/ic_play_arrow_black_24dp"
        android:layout_centerVertical="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:id="@+id/tv_trailer_sequence"
        android:layout_width="wrap_content"
        android:layout_height="26dip"
        android:layout_centerVertical="true"
        android:layout_toEndOf="@+id/play_button"
        android:ellipsize="marquee"
        android:gravity="center"
        android:maxLines="1"
        android:text="Description"
        android:textSize="12sp" />

</RelativeLayout>

Y LISTO, obtuve el efecto deseado de ListView(Ahora RecyclerView) dentro de un scollview. Aquí está la Imagen Final de la Interfaz de usuario

En una nota final, creo que reemplazar el RecyclerView fue una mejor elección para mí, ya que mejoró la estabilidad general de la aplicación, y también me ayudó a entender RecyclerView mejor. Si tuviera que sugerir una solución, voy a decir reemplazar su ListView con un RecyclerView.

 1
Author: Pushkaraj Joshi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-06 09:17:51

La solución anterior dada por @Shailesh Rohit funciona perfectamente bien. Hay que hacer algunos trucos.

  1. Si está poniendo la clase helper dentro de la misma clase( clase main), haga que la clase Helper sea estática y getListViewSize() no sea estática.

  2. Lo más importante, escribe " Ayudante.getListViewSize (ListView);" sentencia después de configurar el adaptador por primera vez como "ListView.setAdapter (MyAdapter);" así como cuando usted está usando "MyAdapter.notifyDataSetChanged();"

  3. El uso se muestra a continuación.

    ListView = (ListView) findViewById (R. id. ListView); MyAdapter = nuevo ArrayAdapter (esto, android.R. disposición.simple_list_item_1, listValues); ListView .setAdapter (MyAdapter); Ayudante.getListViewSizelistView (ListView);

    MyAdapter.notifyDataSetChanged(); Ayudante.getListViewSizelistView (ListView);

 1
Author: Tara,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-21 07:31:32

Como de acuerdo a mí, mientras está utilizando setOnTouchListener om padre o hijo detener el desplazamiento de los padres como tocar en el niño de lo contrario detener el desplazamiento del niño como tocar en el padre

 0
Author: sharma_kunal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-16 07:40:38

Use este método y su listview se volverá desplazable dentro de scrollview: -

   ListView lstNewsOffer.setAdapter(new ViewOfferAdapter(
                            ViewNewsDetail.this, viewOfferList));
                    getListViewSize(lstNewsOffer);

void getListViewSize(ListView myListView) {
    ListAdapter myListAdapter = myListView.getAdapter();
    if (myListAdapter == null) {
        // do nothing return null
        return;
    }
    // set listAdapter in loop for getting final size
    int totalHeight = 0;
    for (int size = 0; size < myListAdapter.getCount(); size++) {
        View listItem = myListAdapter.getView(size, null, myListView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    // setting listview item in adapter
    ViewGroup.LayoutParams params = myListView.getLayoutParams();
    params.height = totalHeight
            + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
    myListView.setLayoutParams(params);
    // print height of adapter on log
    Log.i("height of listItem:", String.valueOf(totalHeight));
}
 0
Author: Sudhir Game Developer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-31 12:07:30

Intente esto con ScrollView, no con ListView.

public class xScrollView extends ScrollView
{
    ;
    ;
    @Override
    public boolean onInterceptTouchEvent (MotionEvent ev)
    {
        return false;
    }
}
 0
Author: Kim Sangdeuk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-17 06:55:33

RequestDisallowInterceptTouchEvent (boolean disallowIntercept)

Se llama cuando un hijo no quiere que este padre y sus antepasados intercepten eventos táctiles con onInterceptTouchEvent(MotionEvent). Este padre debe pasar esta llamada a sus padres. Este padre debe obedecer esta solicitud durante la duración del toque (es decir, solo borrar la bandera después de que este padre haya recibido un up o una cancel.

Intenta esta respuesta,

    listview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

// Disallow the touch request for parent scroll on touch of child view
            scrollView.requestDisallowInterceptTouchEvent(true);

            int action = event.getActionMasked();
            switch (action) {
                case MotionEvent.ACTION_UP:
                    scrollView.requestDisallowInterceptTouchEvent(false);
                    break;
            }
            return false;
        }
    });
 0
Author: Ranjith Kumar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-20 08:08:08

Reemplace ListView por RecycleView dentro de ScrollView. funciona sin problemas sin código fuente adicional:

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hung.recycleviewtest.MainActivityFragment"
    >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycle_view"
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:background="@android:color/darker_gray"/>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycle_view_a"
            android:layout_marginTop="40dp"
            android:layout_below="@id/recycle_view"
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:background="@android:color/darker_gray"/>
    </RelativeLayout>

</ScrollView>
 0
Author: HungNM2,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-05 11:20:09

Para ListView dentro de ScrollView use NestedScrollView puede manejar esto funcionalidad muy fácilmente:

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="5dip"/>

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
 0
Author: Puneet Kumar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-06 15:24:13

He tenido este error.Y mi solución es la siguiente:

1. Crear una vista de lista personalizada que no se puede desplazar

public class NonScrollListView extends ListView {

public NonScrollListView(Context context) {
    super(context);
}
public NonScrollListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}
public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
                Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();    
}

}

2. Usar la clase personalizada anterior para el archivo xml

  <com.Example.NonScrollListView
        android:id="@+id/lv_nonscroll_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </com.Example.NonScrollListView>

Espero lo mejor para ti.

 0
Author: Hai Rom,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-11 04:40:01

Encontré una solución para eso, En lugar de usar scrollview, puede usar addHeaderView y addFooterview de listview

Aquí está mi fragmento,

//  create separate layout and add it dynamically
    scrollview=getLayoutInflater().inflate(R.layout.yourlayout,null);
    lv=(ListView)listview.findViewById(R.id.listView2);
    lv.addHeaderView(scrollview);
    lv.setContentView(lv);

Ahora, con la vista de lista, su diseño también se puede desplazar. ¡Disfrútalo!!!

 0
Author: Jyoti JK,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-02 06:06:45

Sé que esta pregunta se hizo hace mucho tiempo, pero quien se quede atascado por ahora puede resolver esto agregando esta línea a su ListView

android:nestedScrollingEnabled="true"

Por Ejemplo -

                    <ListView
                    android:id="@+id/listView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:nestedScrollingEnabled="true" />
 0
Author: Karan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-02 16:57:09

Reemplaza ScrollView por android.apoyo.v4.widget.NestedScrollView dentro de xml. se ejecuta

1) Uso en XML:::: android.support.v4.widget.NestedScrollView

En Lugar de:::: ScrollView

2) Y use para la vista de lista de esta manera usando NonScrollListView en el archivo cs:

public class NonScrollListView extends ListView {    

    public NonScrollListView(Context context) {    
        super(context);
    }    
    public NonScrollListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
                Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    }    
}    

3) Finalmente use este código para identificar scrollview en el archivo cs:

NonScrollListView listView = (NonScrollListView) view.findViewById(R.id.listview);
 0
Author: Amit yadav,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-20 09:05:40

No le dé vista de desplazamiento a ListView, porque tiene esa configuración predeterminada

<ListView
    android:cacheColorHint="#00000000"
    android:id="@+id/ListView01"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" />
 -1
Author: rajsimen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-29 19:21:12

No puede agregar una vista de lista en una vista de desplazamiento, ya que la vista de lista también se desplaza y habría un problema de sincronización entre el desplazamiento de la vista de lista y el scoll de la vista de desplazamiento. Puede hacer una vista de lista personalizada y agregar este método a ella.

@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /*
     * Prevent parent controls from stealing our events once we've gotten a touch down
     */
    if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
        ViewParent p = getParent();
        if (p != null) {
            p.requestDisallowInterceptTouchEvent(true);
        }
    }
    return false;
}
 -1
Author: Gopal Srivastava,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-01 19:15:19