Gridlayout в Scrollview для Android - PullRequest
       11

Gridlayout в Scrollview для Android

0 голосов
/ 03 сентября 2018

Я хотел бы реализовать приложение, которое заполняет сетку с предопределенным макетом. Сетка не прокручивается, она показывает весь вид сетки. Я не могу заставить его работать на API 19. Я искал все, но не повезло. Если это невозможно реализовать, что может быть альтернативой для этого?
Мой основной макет:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/backgroundGrey"
    android:fillViewport="true"
    tools:context=".MainActivity">

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

    <android.support.v7.widget.GridLayout
        app:columnCount="2"
        app:rowCount="3"
        app:alignmentMode="alignMargins"
        app:columnOrderPreserved="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="8dp">

        <!-- Row 1 -->
        <!-- column 1 -->
        <android.support.v7.widget.CardView
            android:layout_height="0dp"
            android:layout_width="0dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

            <include layout="@layout/taxi_snippet" />

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

        <!-- column 1 -->
        <android.support.v7.widget.CardView
            android:layout_height="0dp"
            android:layout_width="0dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

            <include layout="@layout/taxi_snippet" />

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

        <!-- Row 1 -->
        <!-- column 1 -->
        <android.support.v7.widget.CardView
            android:layout_height="0dp"
            android:layout_width="0dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

            <include layout="@layout/taxi_snippet" />

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

        <!-- column 1 -->
        <android.support.v7.widget.CardView
            android:layout_height="0dp"
            android:layout_width="0dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

            <include layout="@layout/taxi_snippet" />

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

        <!-- Row 1 -->
        <!-- column 1 -->
        <android.support.v7.widget.CardView
            android:layout_height="0dp"
            android:layout_width="0dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

            <include layout="@layout/taxi_snippet" />

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

        <!-- column 1 -->
        <android.support.v7.widget.CardView
            android:layout_height="0dp"
            android:layout_width="0dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

            <include layout="@layout/taxi_snippet" />

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

        <!-- column 1 -->
        <android.support.v7.widget.CardView
            android:layout_height="0dp"
            android:layout_width="0dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

            <include layout="@layout/taxi_snippet" />

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

        <!-- column 1 -->
        <android.support.v7.widget.CardView
            android:layout_height="0dp"
            android:layout_width="0dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">


            <include layout="@layout/taxi_snippet" />
        </android.support.v7.widget.CardView>

        <!-- column 1 -->
        <android.support.v7.widget.CardView
            android:layout_height="0dp"
            android:layout_width="0dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">

            <include layout="@layout/taxi_snippet" />
        </android.support.v7.widget.CardView>

        <!-- column 1 -->
        <android.support.v7.widget.CardView
            android:layout_height="0dp"
            android:layout_width="0dp"
            app:layout_columnWeight="1"
            app:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">
            <include layout="@layout/taxi_snippet" />

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

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



    </LinearLayout>
</ScrollView>


мой taxi_snippet layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10sp"
    android:background="@drawable/yellowborder"
    android:layout_gravity="center_vertical|center_horizontal"
    android:orientation="vertical"
    android:weightSum="10">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:background="@color/snippetBackgroundYellow">

        <ImageView
            android:layout_width="match_parent"
            android:layout_marginBottom="-5sp"
            android:layout_height="match_parent"
            android:baselineAlignBottom="true"
            android:src="@drawable/ic_driver" />

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        android:layout_weight="4">

        <TextView
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dip"
            android:gravity="center"
            android:fontFamily="sans-serif"
            android:textSize="20sp"
            android:textStyle="bold"
            android:textColor="@color/buttonYellow"
            android:text="Name" />

        <TextView
            android:id="@+id/telefon"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dip"
            android:gravity="center"
            android:textSize="18sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif-thin"
            android:textColor="@color/white"
            android:text="@string/telNumber" />

        <TextView
            android:id="@+id/openingHour"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dip"
            android:gravity="center"
            android:textSize="18sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif-thin"
            android:textColor="@color/white"
            android:text="@string/openingHours" />

        <TextView
            android:id="@+id/availableAtNight"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dip"
            android:gravity="center"
            android:textSize="18sp"
            android:textStyle="bold"
            android:fontFamily="sans-serif-thin"
            android:textColor="@color/white"
            android:text="@string/atNight" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0sp"
            android:layout_weight="1"
            android:layout_marginLeft="1.5dp"
            android:layout_marginRight="1.5dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_height="match_parent"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:src="@drawable/ic_phone"
                android:padding="10sp"
                android:background="@color/snippetBackgroundYellow" />

            <ImageView
                android:layout_height="match_parent"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:padding="6sp"
                android:src="@drawable/ic_favorite"
                android:background="@color/backgorundGrey" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

enter image description here

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...