1

我在Android应用程序中定制了View,它被放在HorizontalScrollView的内部,如图所示。滚动查看发生在触摸滚动的位置后

<HorizontalScrollView 
      android:id="@+id/feedBackScroller" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scrollbars="none"> 

      <com.my.views.OfflineFeedbackView 
       android:id="@+id/feedBackView" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_marginTop="@dimen/session_rec_page_title_bar_height" 
       android:layout_marginBottom="@dimen/session_rec_page_ctrl_bar_height"/> 

</HorizontalScrollView> 

OfflineFeedbackView表明,我玩的音频轨道的间隔赛道,我滚动通过基于当前播放时间调用scrollTo(newXPos, newYPos)这一观点。我面临的问题是,如果通过触摸滚动屏幕然后开始播放,滚动的引用似乎在我的视图中发生变化,并且滚动发生在通过触摸滚动到的位置。我浏览了API文档,发现scrollTo(newXPos, newYPos)内部调用onScrollChanged(int l, int t, int oldl, int oldt),其中oldloldt分别是旧的水平和垂直原点。所以,我从中解释的是,当我通过触摸屏幕来滚动这些原点值时就会发生变化。所以,我也试过拨打onScrollChanged(newX, newY, 0, 0),但这只是冻结了屏幕,没有滚动。难道我做错了什么?什么可以是其他更好的方法来处理这个问题?

回答

0

这里的问题看起来像你说的那样Horizo​​ntalScrollView的位置在触摸时会发生变化。

所以,一个解决方案可能会发现你的滚动视图的初始左上位置

HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.ScrollView); 
int x, y; 
x = hsv.getLeft(); 
y = hsv.getTop(); 

,总是你的子视图相对滚动到这些存储的X,Y位置即

childView.scrollTo(x+newXPos,y+newYPos);