2014-05-14 5 views
1

Android 프로젝트에 문제가 있습니다.RelativeLayout이있는 Android ScrollView가 작동하지 않습니다.

이미지 목록이 포함 된보기를 만들었고 Nexus 5 화면에서 모든 이미지를 볼 수 있지만 가장 작은 전화에서이 이미지 중 일부가 겹칩니다.

그래서 ScrollView를 삽입하기로 결정했지만 많은 오류가 있습니다.

많은 비슷한 질문을 발견했지만 나에게 맞는 것은 없습니다.

나를 도와 줄 사람이 있습니까? 있는 ScrollView없이

이 잘 작동 코드는 다음과 같습니다

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ScrollView01" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true" 
android:scrollbars="none" > 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#ff0088ff" 
android:clickable="false"> 



<ImageView 
    android:layout_width="70dp" 
    android:layout_height="70dp" 
    android:id="@+id/imageView" 
    android:src="@drawable/icona_pr" 
    android:layout_marginLeft="28dp" 
    android:contentDescription="@string/icona_pr" 
    android:onClick="apriPreliminare" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<ImageView 
    android:layout_width="70dp" 
    android:layout_height="70dp" 
    android:id="@+id/imageView2" 
    android:src="@drawable/icona_p" 
    android:contentDescription="@string/icona_p" 
    android:onClick="apriPesantezza" 
    android:layout_above="@+id/imageView3" 
    android:layout_alignLeft="@+id/imageView" 
    android:layout_alignStart="@+id/imageView" /> 

    [...] 
</RelativeLayout> 
</ScrollView> 

안드로이드 Studio에서 내가 디자인 탭은 내가 더 긴 화면을 볼 수 미리보기를 선택

. Nexus 5에서는 잘 돌아가며 변경 사항은 없지만 Galaxy S2에서는 처음 두 ImageView가 겹칩니다.

+1

입니다. 오류는 무엇입니까? –

+0

나는 많은 다른 코드를 사용하여 ScrollView를 삽입하려고했는데 모든 코드가 많은 오류를 발생시킨다. 그래서 나는 내 코드로 구현하는 방법을 알고 싶다. – Gualty

+1

첫 번째 단계는 시도한 것을 보여주는 것입니다 (작동하지 않더라도). 두 번째 단계는 오류가 실제로 말하고 어디서 오는 것인지 알려주는 것입니다. IDE 오류입니까? 그것은 컴파일합니까? logcat에서 볼 수있는 런타임 오류입니까? –

답변

1

여기 난 당신이 게시 코드에있는 ScrollView이 표시되지 않는 레이아웃

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

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:clickable="false" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/imageView" 
      android:layout_width="70dp" 
      android:layout_height="70dp" /> 

     <ImageView 
      android:id="@+id/imageView2" 
      android:layout_width="70dp" 
      android:layout_height="70dp" /> 

     <ImageView 
      android:id="@+id/imageView3" 
      android:layout_width="70dp" 
      android:layout_height="70dp" /> 

     <ImageView 
      android:id="@+id/imageView4" 
      android:layout_width="70dp" 
      android:layout_height="70dp" /> 

     <ImageView 
      android:id="@+id/imageView5" 
      android:layout_width="70dp" 
      android:layout_height="70dp" /> 

     <ImageView 
      android:id="@+id/imageView6" 
      android:layout_width="70dp" 
      android:layout_height="70dp" /> 
    </LinearLayout> 

</ScrollView> 
+0

대단히 감사합니다! 지금은 완벽합니다.) – Gualty

+0

다른 문제가 있습니다. 배경색을 설정했지만 Nexus 5와 같은 화면에서는 페이지 끝 부분에 a 부분이 표시됩니다. 왜냐하면 스크롤 뷰가 내용에 맞기 때문입니다. 상대방의 화면 크기와 맞도록 배경을 설정하려면 어떻게해야합니까 ?? – Gualty

+0

u 그냥 상대 레이아웃 대신 scrollview의 배경을 설정합니다. –

0

ScrollView는 전체 레이아웃의 상위보기 인 경우 하나의 대상 레이아웃을 포함해야하며 xmlns 태그도 추가합니다.

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

    <RelativeLayout android:layout_width="match_parent" 
        android:layout_height="match_parent"> 

     //Other staff in here 

    </RelativeLayout> 

</ScrollView> 
+0

첫 번째 게시물에서 코드를 업데이트했으며 게시 한 코드와 동일한 코드를 업데이트했지만 처음 두 이미지는 겹칩니다. 가장 작은 화면 – Gualty

+0

죄송 합니다만 RelativeLayout을 사용하려는 경우 "layout_below", "layout_above", "leftOf", "rightOf"등의 태그를 사용하여 자식 뷰와의 상대 연결을 설정해야합니다. http : //developer.android.com/reference/android/widget/RelativeLayout.html –

+0

내 코드를 수정하여 ScrollView를 삽입하도록 도와 줄 수 있습니까? – Gualty

관련 문제