2010-04-13 85 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>