ScrollView with Images and LinearLayout

0

I'm 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

IalreadytriedtotakeScrollView,butthescreenofthecellphonecutsthelasttwoimagesbelowofthefilmTheReturnandtoKill

ButwhenIaddtheScrollViewsoIcanscrolldownthescrollbarandviewthemoviesbelowReturnandKillithasthefollowingerror,ScrollViewcanonlyonedirectchild

<?xmlversion="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>
    
asked by anonymous 21.08.2017 / 05:29

2 answers

0

In your case you have 2 children for the scrollview, and the same only accepts a child view for its hierarchy .. I'll give you an example of right and wrong way.

RIGHT

        <?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 the 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 the scrollview this time has 2 children LinearLayout, this will cause the error:

  

a scroll view can only have one child

    
21.08.2017 / 14:41
0

The ScrollView only accepts a View / Layout within it.

I can not be sure but it seems to me that in this case, it should be the first element:

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

You will eventually have to adjust the values of android:layout_width and android:layout_height for both ScrollView and the first LinearLayout.

    
21.08.2017 / 12:23