Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

android widget - Disable ScrollView action

In my application i've a line for increasing the width of a widget(by dragging the line to right/left) and i've the ScrollView enabled in the same activity. I need to disable the scroll view action when the user touches the line and when user releases, it should be enabled. The ScrollView should be in visible state but the action of the scroll view should be disabled. Please help me in solving this problem. I've tried with these but none of them is working.

scroll.setEnabled(false); 
scroll.setFocusable(false); 
scroll.setHorizontalScrollBarEnabled(false); 
scroll.setVerticalScrollBarEnabled(false);

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This might be a bit late but I ran into the same problem so my solution is similar to above, had to disable the OnTouchListener as follows:

// Get the ScrollView
final ScrollView myScroll = (ScrollView) findViewById(R.id.display_scrollview);


// Disable Scrolling by setting up an OnTouchListener to do nothing
myScroll.setOnTouchListener( new OnTouchListener(){ 
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true; 
    }
});


// Enable Scrolling by removing the OnTouchListner
tvDisplayScroll.setOnTouchListener(null);    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...