2014-04-27 4 views
1

overscroll을 지원하고 좋은 바운스 효과가있는 내 안드로이드 앱에서 scrollview를 사용하고 있습니다. 처음에 사용자에게 숨겨진 뷰를 추가하고 싶지만 처음 뷰를 넘어 스크롤하면 뷰를 볼 수 있습니다. 어떻게해야합니까? xml을 사용하여이 작업을 수행 할 수 있습니까?스크롤 뷰 위의 뷰 배치

답변

0

LinearLayout에 초기보기와 추가보기를 배치 할 수 있으며 스크롤보기가 작성되면 초기보기로 바로 아래로 스크롤 할 수 있습니다. xml 속성 android:scrollY을 사용하여 초기 스크롤 오프셋을 설정할 수 있습니다.

0

코드를 사용하면이를 분명히 달성 할 수 있습니다. 이 샘플 코드에는 srollview에 15 개의 버튼이 있습니다. 초기 표시를 위해 첫 번째 버튼을 숨 깁니다.

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    final ScrollView hscrollViewMain = (ScrollView)findViewById(R.id.sview); 

    hscrollViewMain.post(new Runnable() { 
     public void run() { 

      Button bt2 = (Button)findViewById(R.id.button2); 
      int nY_Pos = bt2.getTop(); 
      // scroll to top of bt2 
      hscrollViewMain.scrollTo(0,nY_Pos); 
     } 
    }); 
} 

main.xml에

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/sview" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
> 

<LinearLayout 

    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
    <Button 
     android:layout_width="fill_parent" 
     android:id="@+id/bt1" 
     android:layout_height="wrap_content" 
     android:text="Button 1" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 

     android:text="Button 2" /> 

    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Button 3" /> 
       . 
       . 
       . 
    <Button 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Button 15" /> 
    </LinearLayout> 

    </ScrollView> 
+0

여전히 같은 문제에 직면? –