12

LinearLayout이 포함 된 ScrollView로 구성된 조각에 문제가 있습니다. LinearLayout에 흰색 배경이 있고 배경색이 스크롤 된 종이처럼 보이는 효과를 만들려고합니다. 이를 달성하기 위해 노력하고있는 방법은 조각의 전체 공간을 ScrollView가 차지하도록하여 내부의 LinearLayout에 android:layout_margin="16dp"이라는 "종이"주위에 공간을 생성하는 것입니다.ScrollView가 내부 LinearLayout의 하단 여백 끝으로 스크롤하지 않습니다.

이렇게하면 ScrollView의 스크롤 막대가 채색 된 배경 영역에 나타나고 상단의 여백이 내용과 함께 스크롤되고 하단의 여백은 끝에 도달 할 때만 스크롤됩니다.

불행하게도이 구성에서 ScrollView는 끝까지 스크롤하지 않으며 실제로는 매우 작은 양의 텍스트를 맨 아래로 자릅니다. 나는 ScrollView가 수직 스크롤링 거리에서 자녀의 마진을 고려하지 않았다고 생각한다. 이 문제를 해결하기 위해 FrameLayout에 LinearLayout을 래핑했습니다. 그러나 불필요한 것처럼 보입니다. 이 불필요한 컨테이너를 제거하는 방법에 대한 조언을 주시면 감사하겠습니다.

참고 : ScrollView에서 android:padding="16dp"을 설정하고 여백을 스크래핑하면 스크롤 위치에 관계없이 패딩이 모든 네 모서리에 연속적으로 나타나므로 원하는 효과가 없습니다.

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

    <!-- This FrameLayout exists purely to force the outer ScrollView to respect 
     the margins of the LinearLayout --> 
    <FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="10dp" 
      android:layout_margin="16dp" 
      android:background="@color/page_background" > 

      <TextView 
       android:id="@+id/article_title" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:textIsSelectable="true" /> 

      <TextView 
       android:id="@+id/article_content" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textIsSelectable="true" /> 

     </LinearLayout> 
    </FrameLayout> 
</ScrollView> 
+1

는'안드로이드 설정 시도? –

+0

@AdilSoomro 예, 기쁨이 없습니다. ScrollView의 크기는 실제 문제가 아니며 적절하게 사용할 수있는 공간을 채 웁니다. 즉각적인 하위 항목에 여백이있을 때 내용의 맨 끝으로 스크롤하는 것을 허용하지 않습니다.나는이 문제가 스크롤 영역을 계산할 때 자녀의 마진을 고려하지 않기 때문에 발생한다고 생각합니다. –

답변

0

나는 FrameLayout 없애 줄 레이아웃 높이로 match_parent 세트로 LinearLayoutScrollView의 아이를합니다. 그래도 문제가 해결되지 않으면 하단 여백을 의 마지막 항목으로 원하는 높이와 배경을 가진 임의의 다른 View으로 교체하는 것이 좋습니다.

+0

Match_parent가 scrollView에 있어야합니다. 그리고 scrollView의 자식은 heigh = "wrap_content"여야합니다. –

+0

아 좋은 지적이야. 후자의 옵션이 아마도 가장 좋을 것입니다. – Wenger

+2

이러한 조합 중 어느 것도이 문제를 해결하지 못합니다. LinearLayout의 끝에 원하는 마진 높이의 추가 뷰를 추가하는 것은 FrameLayout에 배치하는 것보다 약간 더 심합니다. ScrollView가 이런 식으로 동작하고 위쪽 및 아래쪽 여백을 무시하는 이유는 무엇입니까? –

5

ScrollView 콘텐츠 레이아웃에 위쪽 여백이있을 때 콘텐츠의 끝에 아무 것도 나타나지 않는 것을 기억합니다.

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

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="10dp" 
     android:layout_margin="16dp" > 

     <TextView 
      android:id="@+id/article_title" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textIsSelectable="true" 
      android:background="@color/page_background" /> 

     <TextView 
      android:id="@+id/article_content" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textIsSelectable="true" 
      android:background="@color/page_background" /> 


     <!-- Add a little space to the end --> 
     <View 
      android:layout_width="fill_parent" 
      android:layout_height="30dp" /> 

    </LinearLayout> 
</ScrollView> 

내가 완전히 위/아래 여백을 피하기 위해 LinearLayout의 시작도 유사한 빈 뷰를 사용 : 나는 LinearLayout의 끝에 빈보기를 추가, 약간의 해킹으로 문제를 해결했다.

편집 : 방금 끝 부분에 도달하면 "종이"의 끝이 나타나길 원했습니다. 이 경우 레이아웃 자체 대신 배경색을 TextView으로 설정할 수 있습니다. 그런 다음 제목과 기사 사이에 여백이 없는지 확인하십시오 (분리로 채우기 사용).

EDIT2 : 질문을 받았을 때 확인하는 법을 배워야합니다. 글쎄, 아마도 누군가에게 도움이 될지도 모릅니다. :)

1

질문은 오래되었지만 FrameLayout을 감쌀 때 ScrollView가 잘못 작동하는 문제가있었습니다. 또한 포함 된 레이아웃의 여백을 고려하지 않는 것입니다. FrameLayout을 올바르게 측정해야하는 다른 단일 자식 LinearLayout으로 바꿀 수 있습니다. 나는 완전히 FrameLayout이를 제거하고 단순히 내부 레이아웃에 패딩 요약 마진을 추가 한 것 :은`ScrollView`에 layout_height = "fill_parent"`:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="26dp" 
      android:background="@color/page_background" > 
<!--...--> 
관련 문제