0

I have grid view calendar in my application.But my grid view is not getting a full view in different screen size.It show only half of the page viewing instead of full view.So i am trying to set the row item's height and width statically in my row.xml file based on the different screen size(Mdpi,Hdpi,Xhdpi).This will be working fine in some types of screen size instead of all screen size.So how do i solve this problem...

Grid Layout:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    android:id="@+id/gridheader"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:background="@drawable/buttonframe"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="left" >

        <TextView
            android:id="@+id/gridprevious"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:clickable="true"
            android:drawableLeft="@drawable/calendar_previous"
            android:gravity="center_horizontal"
            android:padding="5dp"
            android:textColor="@color/white"
            android:textSize="14sp"
            android:textStyle="bold" />
    </LinearLayout>

    <TextView
        android:id="@+id/gridtitle"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:textColor="#939598"
        android:textSize="15sp"
        android:textStyle="bold" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/title"
        android:gravity="right" >

        <TextView
            android:id="@+id/gridnext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginRight="10dp"
            android:clickable="true"
            android:drawableRight="@drawable/calendar_next"
            android:gravity="center_horizontal"
            android:padding="5dp"
            android:paddingLeft="5dp"
            android:textColor="@color/white"
            android:textSize="14sp"
            android:textStyle="bold" />
    </LinearLayout>
</RelativeLayout>

<RelativeLayout
    android:id="@+id/layoutidDays"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="left" >

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".08"
            android:background="#666666"
            android:gravity="center"
            android:text="@string/sunday" />

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".08"
            android:background="#666666"
            android:gravity="center"
            android:text="@string/monday" />

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".08"
            android:background="#666666"
            android:gravity="center"
            android:text="@string/tuesday" />

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".08"
            android:background="#666666"
            android:gravity="center"
            android:text="@string/wednesday" />

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".08"
            android:background="#666666"
            android:gravity="center"
            android:text="@string/thursday" />

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".08"
            android:background="#666666"
            android:gravity="center"
            android:text="@string/friday" />

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight=".08"
            android:background="#666666"
            android:gravity="center"
            android:text="@string/saturday" />
    </LinearLayout>
</RelativeLayout>

<LinearLayout
    android:id="@+id/gridlayoutid"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#666666" >

    <GridView
        android:id="@+id/gridviewid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:horizontalSpacing="1.5dp"
        android:stretchMode="columnWidth"
        android:numColumns="7"
        android:verticalSpacing="1.5dp" />
</LinearLayout>

Grid Row Layout:(row.xml)

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="50dp"
    android:layout_height="65dp"    
    android:orientation="vertical" >

    <TextView
        android:id="@+id/griddate"
        android:layout_width="50dp"
        android:layout_height="27dp"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:textColor="#5C943B"
        android:textSize="17sp"
        android:textStyle="bold" >

    </TextView>

    <TextView
        android:id="@+id/gridstatusRemainTask"
        android:layout_width="50dp"
        android:layout_height="19dp"
        android:textColor="#FF0000"
        android:textStyle="bold"
        android:layout_gravity="center_horizontal"
        android:layout_marginRight="2dp"
        android:gravity="center"
        android:textSize="15sp" />

    <TextView
        android:id="@+id/gridstatusFinishTask"
        android:layout_width="50dp"
        android:layout_height="19dp"
        android:textColor="#00AEEF"
        android:textStyle="bold"
        android:layout_gravity="center_horizontal"
        android:layout_marginRight="2dp"
        android:gravity="center"
        android:textSize="15sp" />

</LinearLayout>

My layout view: enter image description here

I want output the following manner.

enter image description here

Satheesh
  • 1,722
  • 25
  • 35
  • instead of reinventing the wheel,I would suggest you to grab and modify UI with [this library](https://github.com/roomorama/Caldroid) – Mehul Joisar Dec 24 '13 at 09:33
  • Its hard to know by just looking at the XML layout. But just check the parent view if it has any margin or padding for child (GridView) you are placing. – Tabrej Khan Dec 24 '13 at 09:42

2 Answers2

1

Set the height and width of the layout of your GridView.

        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

then, set height and width of your GridView to fill_parent as well. Hope this works.

Check following link and modify your Xml file. As the code you are using very hard to understand. And set GridView height and width easily.

Android Calendar Sample

Kanwaljit Singh
  • 4,339
  • 2
  • 18
  • 21
0

Instead of using Linear Layout try Relative Layout:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="90dp"
    android:layout_height="90dp"
    android:background="@color/reaction_color_selected">
    <TextView
        android:id="@+id/num_events_per_day"
        style="@style/calendar_event_style"
        android:layout_gravity="right"
        android:text="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </TextView>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="New York" />

</RelativeLayout>
Srikanth Roopa
  • 1,782
  • 2
  • 13
  • 19