2015-03-13 110 views

回答

1

您可以将scrollViews设置为onTouchListener,并让其他scrollViews随其滚动。我很久以前也有过这种情况。你可以做的伎俩,例如:

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; 
    } 

}); 

那是我在这个问题的解决方案:listening to scroll events horizontalscrollview android

对我来说它工作得很好......

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> 

添加子水平滚动视图成这个表格的布局动态像

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); 
0

我通过获得滚动更改甚至解决吨。也顺利滚动。

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); 
         } 

       } 
      }); 
相关问题