Question

I have a problem with my Android project.

I created a view with a list of images and on a Nexus 5 screen I can see all these images, but on a smallest phone some of these images are overlapping.

So I decided to insert a ScrollView but I see lots of errors.

I found lots similar question but nothing works for me.

Can someone help me?

Without ScrollView this is the code that works fine:

 <?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>

When in Android Studio I select the Design Tab to see a preview I see a longer screen. On a Nexus 5 It seems to works fine, nothing change, but on a Galaxy S2 The first 2 ImageView are overlapping.

Was it helpful?

Solution

here is your layout

<?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>

OTHER TIPS

ScrollView must contain your ONE target layout, if it is parent view of whole layout also add xmlns tag.

<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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top