0

I am considering about the white blank spacing.

I don't know the reason why white spacing exist in my gridview.

I attached '.xml' and the 'result screen shot. '

I am trying use the gravity things.. but It dosen't work.

Could anyone help me??

...I got stackoverflow error 'It looks like your position is mostly code...

<?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:background="#fff"
    android:orientation="vertical"
    android:weightSum="1">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="10dp"
        android:layout_weight="0.2">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:background="@drawable/set_border"
            android:gravity="center"
            android:text="@string/msg_diary_plan"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.53"
        android:orientation="vertical"
        android:weightSum="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.15"
            android:orientation="horizontal"
            android:weightSum="1">

            <Button
                android:id="@+id/btn_backmonth"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="0.1"
                android:background="@android:color/transparent"
                android:text="" />

            <TextView
                android:id="@+id/tv_date"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_gravity="center"
                android:layout_weight="0.8"
                android:background="@android:color/transparent"
                android:gravity="center"
                android:paddingLeft="10dp"
                android:textColor="#000"
                android:textSize="20sp" />

            <Button
                android:id="@+id/btn_nextmonth"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="0.1"
                android:background="@android:color/transparent"
                android:text="" />
        </LinearLayout>

        <GridView
            android:id="@+id/gridview"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.85"
            android:listSelector="#ffff"
            android:numColumns="7" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_alarm"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.17"
        android:orientation="horizontal"
        android:visibility="visible"
        android:weightSum="1">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.3"
            android:orientation="vertical"
            android:weightSum="1">

            <Switch
                android:id="@+id/sw_alarm"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Alarm" />
        </LinearLayout>

        <TimePicker
            android:id="@+id/timePicker"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.7"
            android:timePickerMode="spinner" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.1">

        <Button
            android:id="@+id/btn_alarm_submit"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000"
            android:text="SUBMIT"
            android:textColor="@color/white" />
    </LinearLayout>

</LinearLayout>

and the result is enter image description here

and this is the gridview item layout. Thanks

<?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:orientation="vertical"
android:weightSum="1">

<TextView
    android:id="@+id/tv_item_gridview"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="0.8"
    android:textColor="#000" />

<TextView
    android:id="@+id/isDone"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="0.2"
    android:visibility="visible" />

Adrian
  • 301
  • 4
  • 15

1 Answers1

2

It is because you have yout item layout set to match_parent but TextViews to wrap_content. So by default it stays at the start position.

To fix this set your TextViews width to match_parent and gravity to center android:gravity="center"

So your item layout will look as 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"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:weightSum="1">

<TextView
    android:id="@+id/tv_item_gridview"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.8"
    android:gravity="center"
    tools:text="2"
    android:textColor="#000" />

<TextView
    android:id="@+id/isDone"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.2"
    android:gravity="center"
    tools:text="13"
    android:visibility="visible" />
</LinearLayout>
Srijith
  • 1,695
  • 17
  • 29