ScrollView Android中的GridLayout

时间:2018-09-03 09:08:51

标签: android uiscrollview grid-layout

我想实现一个应用程序,该应用程序使用预定义的布局填充了网格布局。网格不可滚动,它显示了整个gridview。我无法使其在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

0 个答案:

没有答案