2015-03-13 200 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); 
         } 

       } 
      }); 
相關問題