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
. Whatever I do match_parent
or wrap_content
but when I am giving it prefix size it's got extended in that size. So what can I do to extend it in full screen?
This is my layout code.
<?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>
This is the reference to how it looks match_parent look . And This is how I want height 500dp .
My row item in GridView
is below.
<?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>
Add android:stretchMode="columnWidth"
in your gridview
Try to use android:stretchMode="columnWidth" inside GridView
<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>
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.