Gridview : How to fill entire space with text view - android

I am creating a calendar using GridView (6 row * 8 column). Each of the cells inside this matrix (6*8) is a TextView (which I create dynamically in my program).
The issue I am facing is, the 6*8 matrix is not filling the entire space available for GridView
I would like to to have the 6*8 matrix take the entire space in GridView rather than leaving some blank space b/w the matrix and the next TextView. Can some one help me on this.
Given below is the xml layout of the Gridview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="8"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:gravity="center"
android:layout_weight="1"
/>
<TextView
android:id="#+id/id_worked"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Result 1 ->"
android:layout_weight="0"
android:textSize="20sp"
/>
</LinearLayout>

Remove the
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
from the GridView element. That shoudld reduce the spacing.
Edit: Using LinearLayout you can do this.
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1"
android:weightSum="6">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">items here</LinearLayout>
</LinearLayout>

Related

How to set the screens size of Grid view to match all screen sizes?

Here i have used a gridview but it is not changing according to the screen size.I think there is a problem with height.the xml used for gridview is given below.
<?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="fill_parent"
android:background="#drawable/bg"
android:orientation="vertical" >
<GridView
android:id="#+id/gridView1"
android:numColumns="3"
android:gravity="center"
android:paddingTop="20dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:stretchMode="columnWidth"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/linearLayout1"
android:layout_centerVertical="true"
>
</GridView>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<com.assuretech.ku.HorizontalMenuBar
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
From what I can see. You need to close the RelativeLayout at the end. I've included my screenshot of your code with it closed. I changed the background to red to see the text.
I guess you are looking for
numColumns = "auto_fit"
as GridView attribute
Firstly you must be using some layout to put your gridview in. Do the following:
Make height and width of the layout to fill parent:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
then, set height and width of your gridview to fill_parent as well.
Well, this is just a supposed solution that you might have been working this way
Hope this works for you.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="30dp">
<GridView
android:id="#+id/grid_images"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="100dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="15dp">
</GridView>
</LinearLayout>

Select elements of the next row of a GridView

I have this xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pantallaPrincipal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textoTitulo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5px"
android:layout_marginRight="5px"
android:layout_marginTop="5px"
android:gravity="center" >
</TextView>
<GridView
android:id="#+id/gridPictos"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5px"
android:horizontalSpacing="8px"
android:stretchMode="columnWidth"
android:verticalSpacing="15px" >
</GridView>
</LinearLayout>
And the gridview runs correctly, but it is possible "jump" from the last element of the first row to the first element of the next row?
The final objective is that the user can contro the entire gridview using only the left and right keys.

Creating a layout for a skype-style text input bubble

In iPhone there is a method on UIImage called stretchableimagewithleftcapwidth which can be used to create a chat bubble to stretch for any size (keeping the corners natural size).
We don't seem to have this in Android so I've set out to make a layout that I can then use as a background image with a FrameLayout. The trouble I'm having at the moment is the top row which consists of 3 columns: the left top corner, the stretchable top, and the right top corner. How do I get the left and right top corners to remain fixed size (11dip) and tell the middle to fill any remaining space in the parent? This is what I have so far.
<?xml version="1.0" encoding="UTF-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/layout_bubble_container"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="11dip"
android:id="#+id/layout_bubble_toprow"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/layout_top_leftCorner"
android:layout_width="11dip"
android:layout_height="fill_parent"
android:gravity="left|top">
<ImageView
android:id="#+id/bubble_top_leftcorner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/bubble_lefttop" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_top"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="top|center" >
<ImageView
android:id="#+id/bubble_top"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/bubble_top" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_top_rightCorner"
android:layout_width="11dip"
android:layout_height="fill_parent"
android:gravity="right|top" >
<ImageView
android:id="#+id/bubble_top_rightcorner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/bubble_righttop" />
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="11dip"
android:id="#+id/layout_bubble_middlerow"
android:orientation="horizontal"
android:background="#color/WHITE">
<LinearLayout
android:id="#+id/layout_left"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="left"
android:layout_weight="1">
<ImageView
android:id="#+id/bubble_left"
android:layout_width="11dip"
android:layout_height="fill_parent"
android:src="#drawable/bubble_left" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_right"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right"
android:layout_weight="1">
<ImageView
android:id="#+id/bubble_right"
android:layout_width="11dip"
android:layout_height="fill_parent"
android:src="#drawable/bubble_right" />
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="11dip"
android:id="#+id/layout_bubble_bottomrow"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/layout_bottom_leftCorner"
android:layout_width="11dip"
android:layout_height="fill_parent"
android:gravity="left|top">
<ImageView
android:id="#+id/bubble_bottom_leftcorner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/bubble_leftbottom" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_bottom"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="top|center" >
<ImageView
android:id="#+id/bubble_bottom"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/bubble_bottom" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_bottom_rightCorner"
android:layout_width="11dip"
android:layout_height="fill_parent"
android:gravity="right|top" >
<ImageView
android:id="#+id/bubble_bottom_rightcorner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/bubble_rightbottom" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Here is the layout tree in eclipse if this helps.
Here is what it looks like rendered in the layout editor in eclipse. Note the top and bottom rows not stretching appropriately.
Thanks in advance.
i also needed a chat bubble kind of view in my app so I used a 9 patch drawable as the background image and it is working fine.
check this question:
Why do 9-patch graphics size correctly in the emulator but not on a phone?
And also this link:
http://warting.se/2012/06/04/chat-bubbles-in-android/

GridView items: set relative sizes

I'm trying to display some items in a GridView. I want each item to fill a relative part of the screen (image B) and all I have is GridView take just the space it needs at the top of the screen (image A). The image:
(I want each item sizes over 15-20% height of the main layout)
EDIT : I found this question Percentage width in a RelativeLayout. 'LadaRaider' gives a good answer but I don't know how to use that solution in my GridView cells. This is my layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
<TextView
android:id="#+id/label_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_horizontal"/>
<LinearLayout
android:id="#+id/ll_ok"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lbl_choose"
android:textAppearance="?android:attr/textAppearanceMedium" />
<GridView
android:id="#+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="2"
android:columnWidth="100dp"
android:stretchMode="columnWidth"/>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_wait"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lbl_wait"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
I have also created a custom layout to use in GridView items. It has just a TextView and a background.

Android XML Layout Help: How to layout UI so an ad is always visible

I have playing around with my XML layout for what seems like weeks now, and i just cannot get it to work how i would like it to.
I would like the admob ad to always been visible at the bottom of the screen, I have tried to do it like this, but because the gridview is graphically intensive i think the admob ad is being left behind somewhat.(It only shows 30% of the time, roughly)
Hopefully someone will be able to show me how to lay it out correctly. I.E Force the ad at the bottom of the screen!
Thanks
Lucy
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:id="#+id/ImageView03"
android:src="#drawable/banner_gallery"
android:layout_height="60dp"
android:layout_width="fill_parent"></ImageView>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:columnWidth="90dp"
android:numColumns="auto_fit" android:verticalSpacing="7dp"
android:horizontalSpacing="7dp" android:stretchMode="columnWidth"
android:gravity="center" android:layout_gravity="bottom"
android:layout_marginTop="10dp"></GridView>
<RelativeLayout
android:layout_marginTop="-50dip"
android:gravity="bottom"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
</LinearLayout>
Use Relative Layout as parent layout instead of linear layout and use android:layout_alignParentBottom="true" to the relative layout of addview
Try something like this. You only need one RelativeLayout and then layout the different views according to each other,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="#+id/ImageView03"
android:src="#drawable/banner_gallery"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"/>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:columnWidth="90dp"
android:numColumns="auto_fit" android:verticalSpacing="7dp"
android:horizontalSpacing="7dp" android:stretchMode="columnWidth"
android:layout_below="#id/ImageView03"
android:layout_above="#id/ad"
android:layout_marginTop="10dp"/>
<com.admob.android.ads.AdView
android:layout_alignParentBottom="true"
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

Categories

Resources