2013-06-15 2 views
14

에서 여백으로 스크롤하지 않습니다있는 ScrollView는 다음과 같이 내가 간단한 레이아웃을 가지고 바닥

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#D23456" > 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dp" 
    android:background="#FFFFFF" > 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="800dp" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

</ScrollView> 

있는 ScrollView의 배경이 분홍색 및 선형 레이아웃 내부 800dp의 높이와 안드로이드 아이콘 이미지를 가지고 (화면에 맞지 않는). 내가보기를 기대하고있는 것은 이미지 뷰가 분홍색의 배경에 각면 (위쪽, 아래쪽, 왼쪽, 오른쪽)에 10dp의 여백을두고 떠 다니는 것입니다.하지만 맨 아래로 스크롤하면 스크롤 뷰가 스크롤되지 않습니다. 여백, 그래서 스크롤의 하단 핑크색 마진이 아닌 imageview입니다.

어떻게 방지 할 수 있습니까? 이렇게하면 사용자는 페이지가 아직 끝나지 않았다고 생각하고 더 스크롤 할 수 있습니다.

답변

44

나중에 유사한 상황이 @olefevre에 의해 다음 스레드 https://stackoverflow.com/a/16885601/1474471에서 응답되었음을 알게되었습니다.

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#D23456" 
    android:padding="10dp" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#FFFFFF" > 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="800dp" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 
</LinearLayout> 

</ScrollView> 
+1

참고로, 단지 'LinearLayout'일 필요는 없습니다. 나는 'RelativeLayout'을 사용하고 있습니다. – theblang

+0

이것은 해결책입니다 ... 그것은 매력처럼 작동했습니다 ..! @Mehmet Katircioglu – TheFlash

+1

@mattblang에서 언급했듯이 성능면에서 선형 및 상대 레이아웃이 무거운 대신 FrameLayout을 사용하는 것이 좋습니다. – TheIT

0

android:fillViewport="true"ScrollView을 사용하십시오.

예 : this thread.

+0

이 속성을 알고 있지만이 경우에는 작동하지 않습니다 (직접 시도해보십시오). 우리는 뭔가를 놓칠지도 모른다. –

+2

나를 위해 작동하지 않았다. – theblang

6
@Mehmet Katircioglu에 의해 게시 된 솔루션은 잘 작동

,하지만 당신은 해결할 수 : 패딩과 현재의 LinearLayout를 둘러싼 여분의 LinearLayout을 추가하고 내부의 LinearLayout의 레이아웃 마진을 제거

문제를 해결 문제가 단순히 android : layout_margin을에서 android : 패딩으로 변경하는 것입니다. 좋아요 :

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#D23456" 
     android:padding="10dp" > 

     <!-- Your content (ImageView, buttons...) --> 
    <LinearLayout/> 
관련 문제