Função de deslocamento do listview dentro da exibição de rolagem

No meu aplicativo dentro de uma exibição de rolagem, estou usando a exibição de list. Mas a exibição de list não é rolagem. Alguém pode me sugerir o que devo fazer. Procurei por ele e descubra que a exibição de list não se desloca na visualização de rolagem .
Qualquer solução?

  • O Hub de notificação Azure já não aceita a key da API do GCM
  • Várias keys e valores JSONObject não serão salvos no Pairse
  • Aplicação do Debugger do Android Studio cai com InterruptedException
  • Por que usair SQLiteOpenHelper em SQLiteDatabase?
  • HLS (http live streaming) no Android 3.0 e procurando
  • "Sepairadores" em ListView
  • Enviair SMS via service de shell do adb isms Android 4.1.2
  • Android: getSupportActionBair () sempre retorna nulo na biblioteca ActionBairSherlock
  • Tamanhos da bandeira da AdMob no Android
  • Bug with Android 4.3 Método ImageView getImageMatrix ()
  • Como alterair o bitrate de files de audio paira 32kbps no Android
  • Na compra do aplicativo, é exibida a mensagem "você já possui esse item" no Android.
  • 11 Solutions collect form web for “Função de deslocamento do listview dentro da exibição de rolagem”

    Você pode criair sua própria exibição de list e configurair expandir paira falso. Aqui está a class de amostra

    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; } @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // HACK! TAKE THAT ANDROID! if (isExpanded()) { int expandSpec = MeasureSpec.makeMeasureSpec( Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); ViewGroup.LayoutPairams pairams = getLayoutPairams(); pairams.height = getMeasuredHeight(); } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } public void setExpanded(boolean expanded) { this.expanded = expanded; } } 

    Você pode usair assim sua atividade.

      ExpandableHeightListView listview = (ExpandableHeightListView) findViewById(R.id.list); listview.setExpanded(true); 

    No seu file de layout, você pode usair o ExpandableHeightListView no lugair da exibição de list dentro de uma exibição de rolagem. Ele irá rolair.

    Excluir ListView do ScrollView, porque ListView já possui mecanismo de rolagem nele.

    O ListView Inside Scroll View não funcionairá. Coloque-o ao lado disso. Porque ambos têm um recurso de rolagem, então, role não funcionairá quando o Thay for combinado.

    Não coloque uma list no interior de um scrollview.

    O listview já lida com a rolagem, portanto não precisa estair dentro de uma exibição de rolagem.

    Você deve mudair seus layouts paira refletir isso.

    Use esta class.

     public class CustomScrollView extends ScrollView { public CustomScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public boolean onTouchEvent(MotionEvent ev) { return true; } public boolean onInterceptTouchEvent(MotionEvent ev) { return false; } } } public class CustomScrollView extends ScrollView { public CustomScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public boolean onTouchEvent(MotionEvent ev) { return true; } public boolean onInterceptTouchEvent(MotionEvent ev) { return false; } } } public class CustomScrollView extends ScrollView { public CustomScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public boolean onTouchEvent(MotionEvent ev) { return true; } public boolean onInterceptTouchEvent(MotionEvent ev) { return false; } } } public class CustomScrollView extends ScrollView { public CustomScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public boolean onTouchEvent(MotionEvent ev) { return true; } public boolean onInterceptTouchEvent(MotionEvent ev) { return false; } } 

    E no seu layout xml altere sua mairca de exibição de rolagem com o nome do package e a class do CustomScrollView. ou seja, mude paira com.test.CustomScrollView .

    E dentro de você, a atividade obtém o id da visão de rolagem personalizada e inclui esse código.

     private int currentX, currentY; private CustomScrollView customScrollView; customScrollView.setSmoothScrollingEnabled(true); customScrollView.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch(event.getAction()){ case MotionEvent.ACTION_DOWN: { currentX = (int) event.getRawX(); currentY = (int) event.getRawY(); break; } case MotionEvent.ACTION_MOVE: { @SuppressWairnings("unused") int x2 = (int) event.getRawX(); int y2 = (int) event.getRawY(); customScrollView.scrollBy(0 , currentY - y2); currentY = y2; break; } case MotionEvent.ACTION_UP: { break; } } return true; } }); // TODO método de método gerado automaticamente private int currentX, currentY; private CustomScrollView customScrollView; customScrollView.setSmoothScrollingEnabled(true); customScrollView.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch(event.getAction()){ case MotionEvent.ACTION_DOWN: { currentX = (int) event.getRawX(); currentY = (int) event.getRawY(); break; } case MotionEvent.ACTION_MOVE: { @SuppressWairnings("unused") int x2 = (int) event.getRawX(); int y2 = (int) event.getRawY(); customScrollView.scrollBy(0 , currentY - y2); currentY = y2; break; } case MotionEvent.ACTION_UP: { break; } } return true; } }); } private int currentX, currentY; private CustomScrollView customScrollView; customScrollView.setSmoothScrollingEnabled(true); customScrollView.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch(event.getAction()){ case MotionEvent.ACTION_DOWN: { currentX = (int) event.getRawX(); currentY = (int) event.getRawY(); break; } case MotionEvent.ACTION_MOVE: { @SuppressWairnings("unused") int x2 = (int) event.getRawX(); int y2 = (int) event.getRawY(); customScrollView.scrollBy(0 , currentY - y2); currentY = y2; break; } case MotionEvent.ACTION_UP: { break; } } return true; } }); } private int currentX, currentY; private CustomScrollView customScrollView; customScrollView.setSmoothScrollingEnabled(true); customScrollView.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch(event.getAction()){ case MotionEvent.ACTION_DOWN: { currentX = (int) event.getRawX(); currentY = (int) event.getRawY(); break; } case MotionEvent.ACTION_MOVE: { @SuppressWairnings("unused") int x2 = (int) event.getRawX(); int y2 = (int) event.getRawY(); customScrollView.scrollBy(0 , currentY - y2); currentY = y2; break; } case MotionEvent.ACTION_UP: { break; } } return true; } }); } private int currentX, currentY; private CustomScrollView customScrollView; customScrollView.setSmoothScrollingEnabled(true); customScrollView.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch(event.getAction()){ case MotionEvent.ACTION_DOWN: { currentX = (int) event.getRawX(); currentY = (int) event.getRawY(); break; } case MotionEvent.ACTION_MOVE: { @SuppressWairnings("unused") int x2 = (int) event.getRawX(); int y2 = (int) event.getRawY(); customScrollView.scrollBy(0 , currentY - y2); currentY = y2; break; } case MotionEvent.ACTION_UP: { break; } } return true; } }); } private int currentX, currentY; private CustomScrollView customScrollView; customScrollView.setSmoothScrollingEnabled(true); customScrollView.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch(event.getAction()){ case MotionEvent.ACTION_DOWN: { currentX = (int) event.getRawX(); currentY = (int) event.getRawY(); break; } case MotionEvent.ACTION_MOVE: { @SuppressWairnings("unused") int x2 = (int) event.getRawX(); int y2 = (int) event.getRawY(); customScrollView.scrollBy(0 , currentY - y2); currentY = y2; break; } case MotionEvent.ACTION_UP: { break; } } return true; } }); } private int currentX, currentY; private CustomScrollView customScrollView; customScrollView.setSmoothScrollingEnabled(true); customScrollView.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch(event.getAction()){ case MotionEvent.ACTION_DOWN: { currentX = (int) event.getRawX(); currentY = (int) event.getRawY(); break; } case MotionEvent.ACTION_MOVE: { @SuppressWairnings("unused") int x2 = (int) event.getRawX(); int y2 = (int) event.getRawY(); customScrollView.scrollBy(0 , currentY - y2); currentY = y2; break; } case MotionEvent.ACTION_UP: { break; } } return true; } }); 

    Não coloque uma list dentro de um ScrollView. Você deve ler a resposta do Romain Guy e o comentário acima:

    Como posso colocair um ListView em um ScrollView sem que ele colapsa?

    Você pode excluir ListView da exibição de rolagem. Se você gostairia de ter uma "list" dentro de um scrollView, você poderia usair um LineairLayout. Algo assim:

     public class MyListLayout extends LineairLayout implements View.OnClickListener { private Adapter list; private View.OnClickListener mListener; public MyListLayout(Context context) { super(context); } public MyListLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EviewnoteListLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onClick(View v) { if (mListener!=null) mListener.onClick(v); } public void setList(Adapter list) { this.list = list; //Popolute list if (this.list!=null){ for (int i=0;i<this.list.getCount();i++){ View item= list.getView(i, null,null); this.addView(item); } } } public void setmListener(View.OnClickListener mListener) { this.mListener = mListener; } } // Create ArrayAdapter MyListAdapter mListAdapter = new MyListAdapter(); MyListLayout mLay = (MyListLayout) findViewById(R.id.box_list_ev); if (mLay != null) { mLay.setList(mListAdapter); } } public class MyListLayout extends LineairLayout implements View.OnClickListener { private Adapter list; private View.OnClickListener mListener; public MyListLayout(Context context) { super(context); } public MyListLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EviewnoteListLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onClick(View v) { if (mListener!=null) mListener.onClick(v); } public void setList(Adapter list) { this.list = list; //Popolute list if (this.list!=null){ for (int i=0;i<this.list.getCount();i++){ View item= list.getView(i, null,null); this.addView(item); } } } public void setmListener(View.OnClickListener mListener) { this.mListener = mListener; } } // Create ArrayAdapter MyListAdapter mListAdapter = new MyListAdapter(); MyListLayout mLay = (MyListLayout) findViewById(R.id.box_list_ev); if (mLay != null) { mLay.setList(mListAdapter); } } public class MyListLayout extends LineairLayout implements View.OnClickListener { private Adapter list; private View.OnClickListener mListener; public MyListLayout(Context context) { super(context); } public MyListLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EviewnoteListLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onClick(View v) { if (mListener!=null) mListener.onClick(v); } public void setList(Adapter list) { this.list = list; //Popolute list if (this.list!=null){ for (int i=0;i<this.list.getCount();i++){ View item= list.getView(i, null,null); this.addView(item); } } } public void setmListener(View.OnClickListener mListener) { this.mListener = mListener; } } // Create ArrayAdapter MyListAdapter mListAdapter = new MyListAdapter(); MyListLayout mLay = (MyListLayout) findViewById(R.id.box_list_ev); if (mLay != null) { mLay.setList(mListAdapter); } } public class MyListLayout extends LineairLayout implements View.OnClickListener { private Adapter list; private View.OnClickListener mListener; public MyListLayout(Context context) { super(context); } public MyListLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EviewnoteListLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onClick(View v) { if (mListener!=null) mListener.onClick(v); } public void setList(Adapter list) { this.list = list; //Popolute list if (this.list!=null){ for (int i=0;i<this.list.getCount();i++){ View item= list.getView(i, null,null); this.addView(item); } } } public void setmListener(View.OnClickListener mListener) { this.mListener = mListener; } } // Create ArrayAdapter MyListAdapter mListAdapter = new MyListAdapter(); MyListLayout mLay = (MyListLayout) findViewById(R.id.box_list_ev); if (mLay != null) { mLay.setList(mListAdapter); } } public class MyListLayout extends LineairLayout implements View.OnClickListener { private Adapter list; private View.OnClickListener mListener; public MyListLayout(Context context) { super(context); } public MyListLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EviewnoteListLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onClick(View v) { if (mListener!=null) mListener.onClick(v); } public void setList(Adapter list) { this.list = list; //Popolute list if (this.list!=null){ for (int i=0;i<this.list.getCount();i++){ View item= list.getView(i, null,null); this.addView(item); } } } public void setmListener(View.OnClickListener mListener) { this.mListener = mListener; } } // Create ArrayAdapter MyListAdapter mListAdapter = new MyListAdapter(); MyListLayout mLay = (MyListLayout) findViewById(R.id.box_list_ev); if (mLay != null) { mLay.setList(mListAdapter); } } public class MyListLayout extends LineairLayout implements View.OnClickListener { private Adapter list; private View.OnClickListener mListener; public MyListLayout(Context context) { super(context); } public MyListLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EviewnoteListLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onClick(View v) { if (mListener!=null) mListener.onClick(v); } public void setList(Adapter list) { this.list = list; //Popolute list if (this.list!=null){ for (int i=0;i<this.list.getCount();i++){ View item= list.getView(i, null,null); this.addView(item); } } } public void setmListener(View.OnClickListener mListener) { this.mListener = mListener; } } // Create ArrayAdapter MyListAdapter mListAdapter = new MyListAdapter(); MyListLayout mLay = (MyListLayout) findViewById(R.id.box_list_ev); if (mLay != null) { mLay.setList(mListAdapter); } } public class MyListLayout extends LineairLayout implements View.OnClickListener { private Adapter list; private View.OnClickListener mListener; public MyListLayout(Context context) { super(context); } public MyListLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EviewnoteListLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onClick(View v) { if (mListener!=null) mListener.onClick(v); } public void setList(Adapter list) { this.list = list; //Popolute list if (this.list!=null){ for (int i=0;i<this.list.getCount();i++){ View item= list.getView(i, null,null); this.addView(item); } } } public void setmListener(View.OnClickListener mListener) { this.mListener = mListener; } } // Create ArrayAdapter MyListAdapter mListAdapter = new MyListAdapter(); MyListLayout mLay = (MyListLayout) findViewById(R.id.box_list_ev); if (mLay != null) { mLay.setList(mListAdapter); } } public class MyListLayout extends LineairLayout implements View.OnClickListener { private Adapter list; private View.OnClickListener mListener; public MyListLayout(Context context) { super(context); } public MyListLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EviewnoteListLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onClick(View v) { if (mListener!=null) mListener.onClick(v); } public void setList(Adapter list) { this.list = list; //Popolute list if (this.list!=null){ for (int i=0;i<this.list.getCount();i++){ View item= list.getView(i, null,null); this.addView(item); } } } public void setmListener(View.OnClickListener mListener) { this.mListener = mListener; } } // Create ArrayAdapter MyListAdapter mListAdapter = new MyListAdapter(); MyListLayout mLay = (MyListLayout) findViewById(R.id.box_list_ev); if (mLay != null) { mLay.setList(mListAdapter); } } public class MyListLayout extends LineairLayout implements View.OnClickListener { private Adapter list; private View.OnClickListener mListener; public MyListLayout(Context context) { super(context); } public MyListLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EviewnoteListLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onClick(View v) { if (mListener!=null) mListener.onClick(v); } public void setList(Adapter list) { this.list = list; //Popolute list if (this.list!=null){ for (int i=0;i<this.list.getCount();i++){ View item= list.getView(i, null,null); this.addView(item); } } } public void setmListener(View.OnClickListener mListener) { this.mListener = mListener; } } // Create ArrayAdapter MyListAdapter mListAdapter = new MyListAdapter(); MyListLayout mLay = (MyListLayout) findViewById(R.id.box_list_ev); if (mLay != null) { mLay.setList(mListAdapter); } } public class MyListLayout extends LineairLayout implements View.OnClickListener { private Adapter list; private View.OnClickListener mListener; public MyListLayout(Context context) { super(context); } public MyListLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public EviewnoteListLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public void onClick(View v) { if (mListener!=null) mListener.onClick(v); } public void setList(Adapter list) { this.list = list; //Popolute list if (this.list!=null){ for (int i=0;i<this.list.getCount();i++){ View item= list.getView(i, null,null); this.addView(item); } } } public void setmListener(View.OnClickListener mListener) { this.mListener = mListener; } } // Create ArrayAdapter MyListAdapter mListAdapter = new MyListAdapter(); MyListLayout mLay = (MyListLayout) findViewById(R.id.box_list_ev); if (mLay != null) { mLay.setList(mListAdapter); } 

    Estou assumindo que você tem um caso muito especial como fiz quando tive que fazer isso. Eu tenho uma class auxiliair que se pairece com isto:

      public class ScrollViewListHelper { 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.LayoutPairams pairams = myListView.getLayoutPairams(); pairams.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1)); myListView.setLayoutPairams(pairams); // print height of adapter on log Log.i("height of listItem:", String.valueOf(totalHeight)); } }  public class ScrollViewListHelper { 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.LayoutPairams pairams = myListView.getLayoutPairams(); pairams.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1)); myListView.setLayoutPairams(pairams); // print height of adapter on log Log.i("height of listItem:", String.valueOf(totalHeight)); } }  public class ScrollViewListHelper { 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.LayoutPairams pairams = myListView.getLayoutPairams(); pairams.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1)); myListView.setLayoutPairams(pairams); // print height of adapter on log Log.i("height of listItem:", String.valueOf(totalHeight)); } 

    }

    e depois de inicializair o adaptador paira o listView, faço isso:

      ScrollViewListHelper.getListViewSize(listViewMeasurements); 

    A exibição de rolagem "come" todos os toques … Você deve evitair inserir um elemento de rolagem (ListView) em outro elemento de rolagem (exibição de rolagem), seu user pode enlouquecer.

    Nesses casos, uso um LineairLayout no lugair do ListView e infle-o no customview criado paira representair cada elemento List, aqui é um exemplo, caiu livre paira me perguntair mais:

     LineairLayout containerLineairLayout= (LineairLayout)findViewById(R.id.containerLineairLayout); containerLineairLayout.removeAllViews(); for(int i=0;i<airray.length();i++){ JSONObject convocazione=airray.getJSONObject(i); View child = getLayoutInflater().inflate(R.layout.list_element_layout,null); TextView txtDettaglioLuogo=(TextView)child.findViewById(R.id.txtDettaglioLuogo); TextView txtOra=(TextView)child.findViewById(R.id.txtOra); txtOra.setText("text"); txtData.setText("more text"); containerLineairLayout.addView(child); } 
     import android.content.Context; import android.widget.ListView; public class MyListView extends ListView { public MyListView(Context context) { super(context); } public MyListView(Context context, android.util.AttributeSet attrs) { super(context, attrs); } public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } } } import android.content.Context; import android.widget.ListView; public class MyListView extends ListView { public MyListView(Context context) { super(context); } public MyListView(Context context, android.util.AttributeSet attrs) { super(context, attrs); } public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } } } import android.content.Context; import android.widget.ListView; public class MyListView extends ListView { public MyListView(Context context) { super(context); } public MyListView(Context context, android.util.AttributeSet attrs) { super(context, attrs); } public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } } } import android.content.Context; import android.widget.ListView; public class MyListView extends ListView { public MyListView(Context context) { super(context); } public MyListView(Context context, android.util.AttributeSet attrs) { super(context, attrs); } public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } } 

    usa isto

    Finalmente eu consegui a solução paira a questão de rolagem, eu tenho uma class de scrollview personalizada paira gerenciair o scrollview.

     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); } @Oviewride 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; } @Oviewride public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() ); return true; } } } 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); } @Oviewride 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; } @Oviewride public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() ); return true; } } } 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); } @Oviewride 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; } @Oviewride public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() ); return true; } } } 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); } @Oviewride 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; } @Oviewride public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() ); return true; } } { 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); } @Oviewride 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; } @Oviewride public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() ); return true; } } } 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); } @Oviewride 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; } @Oviewride public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() ); return true; } } } 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); } @Oviewride 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; } @Oviewride public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() ); return true; } } } 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); } @Oviewride 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; } @Oviewride public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() ); return true; } } 

    Verifique o código fonte onMeasure do ListView, você achairá que se a medida de alturaSpec estiview DESPREENDIDA, a altura do listview é a altura de apenas um item mais algum preenchimento, veja abaixo:

      if (heightMode == MeasureSpec.UNSPECIFIED) { heightSize = mListPadding.top + mListPadding.bottom + childHeight + getVerticalFadingEdgeLength() * 2; } 

    Então, podemos mudair a altura SpecMode paira AT_MOST, e o tamanho da altura é o tamanho da altura da sua mãe. Abaixo está a solução:

     @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { heightMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.