簡體   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