2010-04-13 3 views
3

Мне нужно показать список, который прокручивается к определенному элементу.ListView и Scroll

как я могу это сделать?

Ori

+0

Искать другие вопросы для "прокрутки программно", есть множество подобных вопросов как здесь, так и на Google. –

ответ

8

вы можете использовать

listView.smoothScrollToPosition(specificPosition); 
7

Это supossed вы используете ListView виджет, то вы можете позвонить setSelection(position) из ListView.

+1

Я предпочитаю это решение, так как «smoothScroll» - это только Android 2.2 и выше, и это может занять очень много, если список большой. –

-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>