Android: ScrollView is not scrolling

荒凉一梦 提交于 2019-12-05 05:42:44
Bhawna Raheja

Change height of scroll view from match_parent to wrap_content. Because scroll view only enable scrolling if its total height is more than the height of parent view. i.e. replace

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

with this code:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true">

I've used the following method several times on several apps. I use a special subclass of ListView:

package com.yourcompany.appname.views;

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

public class NonScrollableListView extends ListView {
    public NonScrollableListView(Context context) {
        super(context);
    }

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

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

    @Override
    protected 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();
    }
}

Then in your layout, instead of using 's, use something like this:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <com.yourcompany.appname.views.NonScrollableListView
        android:id="@+id/listId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
</LinearLayout>

Hope this helps!

You can try this,

   listView.setOnTouchListener(new OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_MOVE) {
        return true; 
    }
    return false;
    }
  });

put list view to another xml and include it like this below

<RelativeLayout 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">
<include layout="@layout/show_message_header" />
    <ScrollView
        android:id="@+id/myscrollview_Show_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/header"
        android:fadingEdge="none"
        android:fillViewport="false"
        android:paddingRight="0dp"
        android:scrollbarAlwaysDrawVerticalTrack="false"
        android:scrollbarSize="0dp"
        android:scrollbarStyle="insideOverlay"
        android:scrollbars="none" >
        <TableLayout
            android:id="@+id/Show_message_dynamic_table"
            android:layout_width="match_parent"
            android:layout_height="fill_parent" >
          <include layout="@layout/desinglayoutforlistviewincludehere" />
         </TableLayout>
    </ScrollView>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!