2010-04-13 117 views
3

我需要显示滚动到特定项目的列表。ListView和滚动

我该怎么办?

大利

+0

搜索了 “编程滚动” 等问题,也有类似的问题负载无论是在SO还是在Google上。 – 2010-04-13 10:59:29

回答

8

可以使用

listView.smoothScrollToPosition(specificPosition); 
7

据supossed您正在使用一个ListView控件,那么你可以调用列表视图的setSelection(position)

+1

我更喜欢这个解决方案,因为'smoothScroll'只是Android 2.2及更高版本,如果列表很大,则可能需要很长时间。 – 2011-08-03 12:45:35

-1

<LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      style="?whiteBackground"> 



     </LinearLayout> 
     <TextView android:id="@+id/textView1" android:layout_width="fill_parent" style="?textTitle" android:layout_height="wrap_content" android:text="Contents"></TextView> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="the following is content..." 
      style="?textSubheader"/> 

     <!-- You cannot have a ListView inside of a ScrollView. This LinearLayout acts like one. --> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      > 
- >
  <ListView android:id="@+id/lv" android:textColor="#444444" 
       android:layout_height="270dip" 
       android:textStyle="bold" 


       android:cacheColorHint="#00000000" android:dividerHeight="2px" 
       android:layout_marginTop="5px" android:layout_width="fill_parent" 
       android:textSize="5px" android:layout_gravity="center"> 
      </ListView> 
<TextView android:id="@+id/any_old_widgetqss" 
    android:layout_width="fill_parent" style="?textTitle" 
    android:layout_height="40px" android:text="MCMS" android:background="@drawable/colorr"></TextView> 

     </LinearLayout> 

    </LinearLayout> 

</ScrollView>