繁体   English   中英

GridView 不走全屏

[英]GridView not taking full screen

I have an android GridView which is stacked between multiple TextView but the problem is GridView is not taking the complete screen it's just extending by the size of the first row of GridView . 无论我做什么match_parentwrap_content但是当我给它前缀大小时,它会以那个大小扩展。 那么我该怎么做才能将它扩展到全屏呢?

这是我的布局代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/b_white">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/light_grey">
        <TextView
            android:id="@+id/t1"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="@string/text"
            android:textColor="@color/f_black"
            android:textSize="15sp"
            android:layout_marginTop="20dp"
            android:drawableEnd="@drawable/ambilwarna_arrow_down"
            android:onClick="nNonClick"/>
        <RelativeLayout
            android:id="@+id/rl1"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <GridView
                android:id="@+id/gridView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:numColumns="4"
                android:padding="5dp"
                android:visibility="visible"
                android:background="@color/l_blue"
                />

        </RelativeLayout>

        <TextView
            android:id="@+id/t2"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="@string/text"
            android:textColor="@color/f_black"
            android:textSize="15sp"
            android:drawableEnd="@drawable/ambilwarna_arrow_down"
            android:onClick="sNonClick"/>
        <RelativeLayout
            android:id="@+id/rl2"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </RelativeLayout>

        <TextView
            android:id="@+id/t3"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="@string/text"
            android:textColor="@color/f_black"
            android:textSize="15sp"
            android:drawableEnd="@drawable/ambilwarna_arrow_down"
            android:onClick="bNonClick"/>
        <RelativeLayout
            android:id="@+id/rl3"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </RelativeLayout>

        <TextView
            android:id="@+id/t4"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="@string/text"
            android:textColor="@color/f_black"
            android:textSize="15sp"
            android:drawableEnd="@drawable/ambilwarna_arrow_down"
            android:onClick="pNonClick"/>
        <RelativeLayout
            android:id="@+id/rl4"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </RelativeLayout>

        <TextView
            android:id="@+id/t5"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="@string/text"
            android:textColor="@color/f_black"
            android:textSize="15sp"
            android:drawableEnd="@drawable/ambilwarna_arrow_down"
            android:onClick="p2NonClick"/>
        <RelativeLayout
            android:id="@+id/rl5"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </RelativeLayout>
    </LinearLayout>
    </ScrollView>
</RelativeLayout>

这是对match_parent 外观的参考。 这就是我想要的高度 500dp

我在GridView中的行项目如下。

<?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="match_parent"
    android:padding="1dp"
    android:orientation="vertical">
    <RelativeLayout
        android:id="@+id/general"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/b_white"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/design"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:scaleType="fitCenter"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/ovel"
            android:padding="5dp"
            android:background="@drawable/frame"
            android:layout_margin="10dp"
            android:tint="@android:color/background_dark" />

        <TextView
            android:id="@+id/d_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="@color/b_white"
            android:padding="1dp"
            android:text="@string/l_general"
            android:textColor="@color/f_black" />
    </RelativeLayout>

</LinearLayout>

在 gridview 中添加android:stretchMode="columnWidth"

尝试在 GridView 中使用 android:stretchMode="columnWidth"

    <RelativeLayout
                android:id="@+id/rl1"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <GridView
                    android:id="@+id/gridView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:numColumns="4"
                    android:padding="5dp"
                    android:visibility="visible"
                    android:background="@color/l_blue"
                    android:stretchMode="columnWidth"
                    />
    </RelativeLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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