简体   繁体   中英

How to make GridView show all component in Android(needless scroll)

Here is my xml file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="@dimen/small_margin"
    android:layout_marginRight="@dimen/small_margin"
    android:background="@android:color/transparent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        android:background="@android:color/transparent"
        android:id="@+id/nested_scrollview"

        >

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

                </RadioGroup>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginBottom="@dimen/medium_margin"
                android:background="@drawable/button_layout_progress_fragment">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginTop="@dimen/medium_margin"
                    android:layout_marginRight="@dimen/small_margin"
                    android:layout_marginLeft="@dimen/small_margin"
                    android:layout_marginBottom="@dimen/small_margin">
                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="Time spent:"
                        android:textStyle="bold"
                        android:textColor="@android:color/black"
                        android:layout_marginRight="@dimen/small_margin"/>
                    <TextView
                        android:textColor="@android:color/black"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="2hrs 37 mins" />
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginRight="@dimen/small_margin"
                    android:layout_marginLeft="@dimen/small_margin"
                    android:layout_marginBottom="@dimen/small_margin"
                    >
                    <TextView
                        android:textColor="@android:color/black"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="New words learnt:"
                        android:textStyle="bold"
                        android:layout_marginRight="@dimen/small_margin"/>
                    <TextView
                        android:textColor="@android:color/black"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="259 words"/>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginRight="@dimen/small_margin"
                    android:layout_marginLeft="@dimen/small_margin"
                    android:layout_marginBottom="@dimen/medium_margin"
                    >
                    <TextView
                        android:textColor="@android:color/black"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="Word roots learnt:"
                        android:textStyle="bold"
                        android:layout_marginRight="@dimen/small_margin"/>
                    <TextView
                        android:textColor="@android:color/black"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="37 words"/>
                </LinearLayout>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="@drawable/button_layout_progress_fragment"
                >
                <GridView
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_height="200dp"
                    android:layout_width="match_parent"
                    android:id="@+id/gvBadges"

                    android:numColumns="3"

                    android:horizontalSpacing="10dp"
                    android:verticalSpacing="10dp"
                    android:gravity="center"
                    android:stretchMode="columnWidth"
                    >
                </GridView>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

I use a scrollview cover gridview inside. And I want to use ONLY scrollview to scroll down the screen, so gridview will show all item inside it. How can I make that? Thank u in advance!

use

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

instead of

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        android:background="@android:color/transparent"
        android:id="@+id/nested_scrollview">

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