2012-06-10 56 views
0

如何滚动ScrollView中的LinearLayout到另一个视图的底部?ScrollView如何滚动到另一个视图的底部

我在我的视图顶部有一个日历imageview。在下面有一个ScrollView,其中包含该月份的事件列表。 ScrollView包含几个LinearLayout,详细说明该月的事件。当用户通过触摸线性布局中的按钮来选择事件时,我想将当前线性布局重新定位到滚动视图的顶部,我该如何实现这一点?

下面是简短的我的布局看起来像一个简短的片段。

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
         android:id="@+id/cirLinLayContainer" 
         android:orientation="vertical" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:background="@drawable/bg_calendar"> 
       <RelativeLayout> 
       <Button    
        android:id="@+id/calLeft" 
        android:background="@drawable/btn_arrowleft_dwn"/> 
       <Button    
        android:id="@+id/calRight" 
        android:background="@drawable/cal_rightnav_button"/> 

       <ImageView android:src="@drawable/cal_september" 
         android:layout_width="match_parent" 
         android:layout_centerHorizontal="true" 
         android:layout_height="wrap_content" /> 
       </RelativeLayout> 

     <ScrollView xmlns:foo="http://schemas.android.com/apk/res/com.demo.android" 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent" 
      android:id="@+id/septemberCalendarScroller"> 

      <LinearLayout android:id="@+id/sepEventLayout01"/> 
      <LinearLayout android:id="@+id/sepEventLayout02"/> 
      <LinearLayout android:id="@+id/sepEventLayout03"/> 
      <LinearLayout android:id="@+id/sepEventLayout04"/> 
     </ScrollView> 
     </LinearLayout> 

回答

0

你可以衡量你的LinearLayout元素的高度,比使用ScrollView.scrollTo()滚动视图相应的位置。

+0

LinearLayout的宽度会给我什么位置?你能举个例子说明你的建议吗? – Byron

+0

对不起,我的意思是身高。更正了答案。 – Moritz

相关问题