2011-10-14 2 views
0

나는 listview를 사용하는 활동을위한이 레이아웃 xml 파일을 가지고있다. 항상 목록보기의 맨 위에서 시작한다는 점만 제외하면 정상적으로 작동합니다. 레이아웃의 맨 위에있는 것이 아닙니다. 내가 테스트 한안드로이드에서 위로 스크롤 막대를 시작하는 방법?

listView.setSelection(0); 

그것은 나를 위해 작동하지 않았다. 화면을 맨 위에서 어떻게 표시 할 수 있습니까?

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<LinearLayout 
android:id="@+id/topLayout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:background="@color/darkbackground" 
> 

<include layout="@layout/subtitle_bar" /> 

<TextView 
android:id="@+id/rankHistory" 
android:text="@string/rankHistory" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="20px" 
android:textSize="24sp" 
android:textStyle="bold" 
android:textColor="#ffffffff" 
android:gravity="center" 
android:layout_gravity="center_horizontal" 
></TextView> 

<ListView android:id="@+id/list" 
android:layout_marginTop="15px" 
android:layout_width="fill_parent" 
android:layout_height="500px" 
android:dividerHeight="15px" 
android:divider="@color/darkbackground" 
> 
</ListView> 

</LinearLayout> 
</ScrollView> 

답변

2

이 시도 :

여기
listView.smoothScrollToPosition(0); 

당신이 샘플 프로젝트 http://www.hrupin.com/2011/10/14/how-to-scroll-listview-to-top-or-other-position

희망을 다운로드 할 수 있습니다, 그것은 당신을 도울!

+0

제안 해 주셔서 감사합니다. 하지만 작동하지 않았다 ... – Kou

+0

시간을 좀주세요. 테스트 프로젝트를 만들고이를 수정하려고합니다. 그것은 나를 위해 역시 재미있다 :) – ihrupin

+0

나는 해결책을 발견했다! !!! listView.smoothScrollToPosition (0); – ihrupin

1

ListView를 ScrollView에 두어서는 안됩니다. ListView 위에 항목을 별도의 XML 파일에 넣은 다음 사용하여 ListView에 헤더로 추가하십시오. listView.addHeaderView(view);

+0

Maria Neumayer에게 제안 해 주셔서 감사합니다. 나는 나중에 그것을 시도 할거야. – Kou

+0

감사! 그것은 일했다! 스크롤하면 뷰도 함께 제공되지만 버전 1.6에는 대안이 없다고 생각합니다. 다시 한 번 감사드립니다! – Kou

+0

오, 나머지 화면을 스크롤하지 않으시겠습니까? 스크롤 막대는 ListView에 연결됩니다. 따라서 ListView가 시작되는 위치 만 표시됩니다. 화면 상단에서 스크롤 막대가 시작되고 전체 화면이 스크롤되지 않으면 혼란 스럽습니다. 레이아웃을 ScrollView가 아니라 LinearLayout에두면 모든 것이 올바르게 표시되지만 스크롤바는 ListView로 시작됩니다. –

관련 문제