简体   繁体   中英

Last cardview in gridview not showing in scrollview layout

image here . I can't see the last cardview in a gridview under a scroll view .The last cardview dosen't show fully.

I have 4 rows and 2 columns specified in Gridview.So in GridView i have 8 Cardviews.
2 cards in each row.

The last row is not visible fully,what can be done

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"
android:layout_height="wrap_content"


<LinearLayout
android:weightSum="15"

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


<GridLayout
   android:elevation="16dp"
    android:paddingBottom="10dp"
    android:rowCount="4"
    android:columnCount="2"
    android:columnOrderPreserved="true"
    android:layout_weight="15"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="16dp"
    android:padding="5dp"
    >

    <!-- ROW 1-->
    <!-- Col 1-->

    <android.support.v7.widget.CardView

        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"



        app:cardBackgroundColor="@color/cardview_light_background"
        app:cardCornerRadius="8dp"
        app:cardElevation="8dp">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_margin="16dp"
            android:orientation="vertical">

            <ImageView

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1"

                android:textAlignment="center"
                android:textColor="@android:color/black"
                android:textSize="18sp"
                android:textStyle="bold" />

        </LinearLayout>

    </android.support.v7.widget.CardView>
    <!-- Col 2-->

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_columnWeight="1"
        android:layout_marginBottom="16dp"

        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_rowWeight="1"
        app:cardBackgroundColor="@color/cardview_light_background"

        app:cardCornerRadius="8dp"
        app:cardElevation="8dp">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_margin="16dp"
            android:orientation="vertical">

            <ImageView

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2"
                android:textAlignment="center"
                android:textColor="@android:color/black"
                android:textSize="18sp"
                android:textStyle="bold" />

        </LinearLayout>

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

I have removed the last 2 rows to reduce code

you need to add this in your cardview xml file :

app:cardUseCompatPadding="true"
card_view:cardElevation="4dp"

I suggest you to use NestedScrollView instead of ScrollView.

Something like below code:

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:scrollbars="none">

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM