You can create a custom ScrollView.
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;
public class CustomScrollView extends ScrollView {
// true se pode mover (nao rolavel)
// false se não pode mover (rolavel)
private boolean mScrollable = true;
public CustomScrollView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// TODO Auto-generated constructor stub
}
public void setScrollingEnabled(boolean enabled) {
mScrollable = enabled;
}
public boolean isScrollable() {
return mScrollable;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// se podemos rolar passar o evento para a superclasse
if (mScrollable)
return super.onTouchEvent(ev);
return mScrollable;
default:
return super.onTouchEvent(ev);
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (!mScrollable)
return false;
else
return super.onInterceptTouchEvent(ev);
}
}
In your xml do this:
<com.mypackagename.CustomScrollView
android:id="@+id/scroll"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView >
</com.mypackagename.CustomScrollView>
So you set your setScrollingEnabled()
method by setting a false
value, as in the example below:
CustomScrollView customScrollView;
customScrollView = (CustomScrollView) findViewById(R.id.scroll);
customScrollView.setScrollingEnabled(false);
Good Luck!