Scrollview with Images and Linearlayout

Asked

Viewed 963 times

0

I am developing a mobile application I would like to leave the application with this visual a horizontal application with an image side by side and with a Scrollview

inserir a descrição da imagem aqui

I already tried to take the Scrollview, but the screen of the phone cuts the last two images below the movie The Return and Kill

inserir a descrição da imagem aqui

But when I add Scrollview so I can scroll down and view the movies below Return and Kill it shows the following error ,Scrollview can only one direct Child

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.tulio.exercicio5.MainActivity">

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="match_parent">


<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"

    >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/aliados" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/chamado3" />

</LinearLayout>


<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"

    >
<ImageView
    android:id="@+id/imageView3"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:srcCompat="@drawable/regresso" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/john_wick" />

</LinearLayout>




<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"

    >

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/residentevil6" />


    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/xxxreativado" />
    </LinearLayout>
    </ScrollView>
    </LinearLayout>

2 answers

0

Scrollview only accepts a View/Layout inside it.

I can’t be sure, but it seems to me that in your case, he should be the first:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.tulio.exercicio5.MainActivity">
    android:layout_width="wrap_content"
    android:layout_height="match_parent">

    <LinearLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"

    ...
    ...
        </LinearLayout>
    </LinearLayout>
</ScrollView>

Eventualmemte will have to adjust the values of android:layout_width and android:layout_height both Scrollview and the first Linearlayout.

0


In your case you have 2 children for scrollview, and it only accepts a child view for your hierarchy.. I will give an example in a correct and incorrect way.

CORRECT

        <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context="com.example.tulio.exercicio5.MainActivity">
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

        <LinearLayout
            <LinearLayout>
            </LinearLayout>
            <LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

Note that we have 3 linear layout within the scrollview, but only one is a direct child of it.

INCORRECT

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.tulio.exercicio5.MainActivity">
    android:layout_width="wrap_content"
    android:layout_height="match_parent">

    <LinearLayout
    </LinearLayout>
    <LinearLayout>
    </LinearLayout>
</ScrollView>

If you stop to parse, you will see that scrollview this time has 2 Linearlayout children, this will cause the error :

a scroll view can only have one Child

Browser other questions tagged

You are not signed in. Login or sign up in order to post.