Несколько изображений в одном экране с ScrollView - PullRequest
0 голосов
/ 16 мая 2018

Я хочу, чтобы на моей первой странице было несколько ImageView's, то есть мой основной класс, как, скажем, Six, сгруппированный в столбцы по два, я хотел сделать это, так как я хочу иметь возможность реализовывать простые прослушиватели по щелчку дляСобытия.Однако я не могу добавить представление прокрутки из-за того, что ScrollView всегда хочет одного ребенка.В настоящее время я использую LinearLayout вертикальную ориентацию.

Вот пример того, чего я хочу достичь с ScrollView в нем

Here is the sample

Мой кодпока что:)

<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"
    xmlns:card_view="http://schemas.android.com/tools"
    android:orientation="vertical"
    tools:context=".Activities.MainActivity"
    tools:showIn="@layout/app_bar_main"
    >


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

        android:layout_marginStart="4dp"
        android:layout_marginEnd="4dp"
        android:paddingTop="60dp">

        <android.support.v7.widget.CardView
            android:layout_width="182dp"
            android:layout_height="245dp"
            app:cardUseCompatPadding="true"
            card_view:cardCornerRadius="4dp"
            >

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/image1"
                android:scaleType="fitXY"
                app:srcCompat="@drawable/events_gradient"
                android:contentDescription="@string/todo" />

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="182dp"
            android:layout_height="245dp"
            app:cardUseCompatPadding="true"
            card_view:cardCornerRadius="4dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/image2"
                android:scaleType="fitXY"
                app:srcCompat="@drawable/kaa_rada"
                android:contentDescription="@string/todo" />
        </android.support.v7.widget.CardView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="4dp"

        android:layout_marginStart="4dp">

        <android.support.v7.widget.CardView
            android:layout_width="182dp"
            android:layout_height="245dp"
            app:cardUseCompatPadding="true"
            card_view:cardCornerRadius="4dp">
            <ImageView
                android:id="@+id/image3"
                android:scaleType="fitXY"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:srcCompat="@drawable/doc"
                android:contentDescription="@string/todo" />

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="182dp"
            android:layout_height="245dp"
            app:cardUseCompatPadding="true"
            card_view:cardCornerRadius="4dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/image4"
                android:scaleType="fitXY"
                app:srcCompat="@drawable/mythgradient"
                android:contentDescription="@string/todo" />
        </android.support.v7.widget.CardView>
    </LinearLayout>

</LinearLayout>

1 Ответ

0 голосов
/ 16 мая 2018

Заключите свой внутренний макет в Scrollview как,

<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"
xmlns:card_view="http://schemas.android.com/tools"
android:orientation="vertical"
tools:context=".Activities.MainActivity"
tools:showIn="@layout/app_bar_main"
>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

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

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

    android:layout_marginStart="4dp"
    android:layout_marginEnd="4dp"
    android:paddingTop="60dp">

    <android.support.v7.widget.CardView
        android:layout_width="182dp"
        android:layout_height="245dp"
        app:cardUseCompatPadding="true"
        card_view:cardCornerRadius="4dp"
        >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/image1"
            android:scaleType="fitXY"
            app:srcCompat="@drawable/events_gradient"
            android:contentDescription="@string/todo" />

    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:layout_width="182dp"
        android:layout_height="245dp"
        app:cardUseCompatPadding="true"
        card_view:cardCornerRadius="4dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/image2"
            android:scaleType="fitXY"
            app:srcCompat="@drawable/kaa_rada"
            android:contentDescription="@string/todo" />
    </android.support.v7.widget.CardView>
</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="4dp"

    android:layout_marginStart="4dp">

    <android.support.v7.widget.CardView
        android:layout_width="182dp"
        android:layout_height="245dp"
        app:cardUseCompatPadding="true"
        card_view:cardCornerRadius="4dp">
        <ImageView
            android:id="@+id/image3"
            android:scaleType="fitXY"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:srcCompat="@drawable/doc"
            android:contentDescription="@string/todo" />

    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:layout_width="182dp"
        android:layout_height="245dp"
        app:cardUseCompatPadding="true"
        card_view:cardCornerRadius="4dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/image4"
            android:scaleType="fitXY"
            app:srcCompat="@drawable/mythgradient"
            android:contentDescription="@string/todo" />
    </android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...