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 way:
<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 then you set up your method setScrollingEnabled()
setting a value false
, as in the example below:
CustomScrollView customScrollView;
customScrollView = (CustomScrollView) findViewById(R.id.scroll);
customScrollView.setScrollingEnabled(false);
Good Luck!
I tried to do, it error and asks to implement a constructor, after that, during execution, it gives an error when I enter Activity that implemented the Customscrollview.
– CristianCotrena
@Cristiancotrena calm, I will make a test and I return you! This will solve your case yes.
– viana
The content of my Scrollview is a Linearlayout (vertical). I forgot to comment on the question..
– CristianCotrena
@Cristiancotrena I improved the answer for you by adding the builders ok?! I tested it here now again and it went all right! Hugs.
– viana
@Cristiancotrena only remembering that the
com.mypackagename
you have to replace by the package where the class isCustomScrollView
. Doing so, it will be all right! As for theLinearLayout
vertical, you can insert normally that works.– viana