0

I have HorizontalScrollView at top header view and I am programmatically adding some HorizontalScrollViews parallel of top HorizontalScrollView. When I scroll top ScrollView then all other should scroll with this and vice versa. How achieve this? Here is image for better understanding

Kalu Khan Luhar
  • 1,044
  • 1
  • 22
  • 35

3 Answers3

1

You can set the scrollViews to onTouchListener and let the other scrollViews scroll with it. I had the same a long time ago. You can do the trick for example:

 scrollOne = (HorizontalScrollView)findViewById(R.id.horizontal_one);
 scrollTwo = (HorizontalScrollView)findViewById(R.id.horizontal_two);

 scrollTwo.setOnTouchListener(new OnTouchListener(){

@Override
public boolean onTouch(View view, MotionEvent event) {
    // TODO Auto-generated method stub

    int scrollX = view.getScrollX();
    int scrollY = view.getScrollY();

    scrollOne.scrollTo(scrollX, scrollY);
                return false;
    }

});

That was my solution in that question:listening to scroll events horizontalscrollview android

For me it worked fine...

Community
  • 1
  • 1
Opiatefuchs
  • 9,800
  • 2
  • 36
  • 49
0
<ScrollView 

    android:id="@+id/ScrollView02" 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:layout_below="@+id/one"
            android:layout_marginBottom="51dp"

            >


<TableLayout
    android:id="@+id/videotable"
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"
    android:background="#ffffff"

     android:layout_marginTop="5dp"
     android:cacheColorHint="#00000000"

  />

</ScrollView>

add your sub horizontal scroll view into this table layout dynamically like

pubs = (TableLayout)findViewById(R.id.videotabls);
        pubs.setStretchAllColumns(true);
        pubs.bringToFront();

HorizontalScrollView hz=new HorizontalScrollView(video.this);   
        lp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
        hz.setBackgroundColor(Color.parseColor("#e6e6e6"));
        hz.setLayoutParams(lp);  
        TableRow tr =  new TableRow(video.this);
tr.setBackgroundColor(Color.parseColor("#e6e6e6"));

        tr.setId(10);

//add all subitems in each layout if reqiuired here

hz.addView(rowlayout);//row layout is a sub layout
        pubs.addView(hz);
        pubs.addView(tr); 
Karthika PB
  • 1,373
  • 9
  • 16
0

I solved by getting scroll change event. Also smoothly scrolling.

ArrayList<HorizontalScrollView> scrArrayList=new ArrayList<HorizontalScrollView>();

    for (int j = 0; j < wrapper.data.size(); j++) {
        LayoutInflater inflater1 = this.getLayoutInflater();
        View itemMain = inflater1.inflate(R.layout.item_scedule, null);
        HorizontalScrollView horizontalScrollView = (HorizontalScrollView) itemMain
                .findViewById(R.id.horizontalScrollView1);
        scrArrayList.add(horizontalScrollView);
    }

    mainScrollView.getViewTreeObserver().addOnScrollChangedListener(
            new OnScrollChangedListener() {
                @Override
                public void onScrollChanged() {
                        for (int i = 0; i < scrArrayList.size(); i++) {
                            int scrollX = scrollView.getScrollX();
                            int scrollY = scrollView.getScrollY();
                            scrArrayList.get(i).scrollTo(scrollX, scrollY);
                        }

                }
            });
Kalu Khan Luhar
  • 1,044
  • 1
  • 22
  • 35