0

I'm writting an application and it looks like this:

picture 1

How you can see there is SeekBar on top and several buttons in HorizontalScrolView below. I would like to use SeekBar to scrolling buttons and this works fine now, but I can't turn off the default way to scroll View (draginng screen). I found similat topic on forum:

Similar Topic

But the problem is, that this way locking whole ScrollView and I cant use it by seekBar and default way - maybe I'm doing something wrong (I did it the same like in the link and this not wort even if I have TRUE in mScrollable parameter). The second problem is that my buttons (which have fill_parent height parameter) are really small.

Question: There is any good way to Lock Scrolling View in default way and use SeekBar to do this??

My Code (default HorizontalScrollView):

 public class MainActivity extends Activity implements SeekBar.OnSeekBarChangeListener {

    static private String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        SeekBar seek = (SeekBar) findViewById(R.id.seekBar);
        final HorizontalScrollView hsv = (HorizontalScrollView)findViewById(R.id.hsv);      

        seek.setMax(948);
        seek.setProgress(474);
        seek.setOnSeekBarChangeListener(this);
        hsv.post(new Runnable() {
            @Override
            public void run() {
                hsv.scrollTo(474, 0);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
        HorizontalScrollView hsv = (HorizontalScrollView)findViewById(R.id.hsv);
        hsv.scrollTo(progress, 0);
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        Log.d(TAG, "Tracking on");
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        Log.d(TAG, "Tracking off");

    }

activity_main:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#0A0A0A"
    android:orientation="vertical" >

    <SeekBar
        android:id="@+id/seekBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <HorizontalScrollView
        android:id="@+id/hsv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scrollbars="none" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

           <!-- BUTTONS CODE - NOT IMPORTANT --> 

        </RelativeLayout>
    </HorizontalScrollView>

</LinearLayout>
Community
  • 1
  • 1
CookieMonssster
  • 658
  • 1
  • 6
  • 19

1 Answers1

1

There is any good way to Lock Scrolling View in default way and use SeekBar to do this??

Edit:

The solution seems to be much simpler, override the HorizontalScrollView class and pass the touch events through the view:

public class MyHScroll extends HorizontalScrollView {

    // the constructors

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return false;
    }

}

The use this class in the layout instead of the default HorizontallScrollView:

<com.your.package.MyHScroll
    android:id="@+id/hsv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="none" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

       <!-- BUTTONS CODE - NOT IMPORTANT --> 

    </RelativeLayout>
</com.your.package.MyHScroll>


Try placing an overlay view on top of the HorizontalScrollView to "absorb" touch events without messing with the HorizontalScrollView itself:
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#0A0A0A"
    android:orientation="vertical" >

    <SeekBar
        android:id="@+id/seekBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout android:layout_width="wrap_content"
        android:layout_height="fill_parent">

    <HorizontalScrollView
        android:id="@+id/hsv"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:scrollbars="none" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

           <!-- BUTTONS CODE - NOT IMPORTANT --> 

        </RelativeLayout>
    </HorizontalScrollView>

    <View android:id="@+id/overlay" android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    </FrameLayout

</LinearLayout>

and then add a OnTouchListener for the overlay widget in the onCreate method to further block touch events:

findViewById(R.id.overlay).setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

The second problem is that my buttons (which have fill_parent height parameter) are really small.

See the layout file above.

user
  • 86,916
  • 18
  • 197
  • 190
  • This works and resolve my problems, but it makes another one - now i cant use buttons ;/ I tried use onDragListener instead of onTouchLister but it crash my app ;/ any ideas? I thought about checking X and Y and check which button it should be and do my method, but it is not too good I think – CookieMonssster Dec 10 '12 at 13:25
  • 1
    @CookieMonssster Yeah, didn't think to much. I've edited my answer, see if that works. – user Dec 10 '12 at 16:24