Used the code provided in admob site
Here is my xml
<?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="#drawable/background_img"
android:orientation="vertical"
android:id="#+id/atozlayout"
>
<GridView
android:id="#+id/gridView1"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="55dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
>
</GridView>
</LinearLayout>
But the logcat shows
E/Ads(4244): Not enough space to show ad! Wants: <480, 75>, Has: <800, 0>
Seems like the layout is creating issue. Please suggest way to fix. Many Thanks.
Your grid is taking up all the space with layout_height="fill_parent".
You can use layout_weight="1" and layout_height="0dp" to tell the grid to take up all the remaining space after other views are shown.
Also are you adding the AdView programmatically? You can place it in the xml below the GridView.
Ex:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_img"
android:orientation="vertical"
android:id="#+id/atozlayout"
>
<GridView
android:id="#+id/gridView1"
android:numColumns="auto_fit"
android:columnWidth="55dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp">
</GridView>
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>
</LinearLayout>
Make sure you replace adUnitId with your value.
Your gridView is greedy. Its eats all available space on the screen. The solution is to switch the top level layout to a Relative layout, and add android:layout_above"#+id/adview" to the GridView and android:layout_alignParentBottom=true to the ad view. This will force the gridview to leave room beneath it for the ad.
According to the Android tab on the page which you linked, you need a <com.google.ads.AdView> view in your layout which seems to be missing from your original post.
Related
I am working on Gridview. Code work fine but it display right side space to view.
how can i adjust space in gridview.my problem is exactly below.
My code xml file code:
<GridView
android:id="#+id/gridExam"
android:gravity="center"
android:numColumns="5"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
Thanks in advance
Your answer would be appreciated.
Give marginLeft to your GridView.
Try using this.
<GridView
android:id="#+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"/>
I am using android:horizontalSpacing attribute in my GridView layout to give horizontal spacing between two columns. But nothing getting change only it give space between the vertical columns.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:stretchMode="columnWidth"
android:numColumns="7" />
</FrameLayout>
This is the above code but i don't understand what is the actual mistake i am doing. You can see in above picture that , there are only black vertical lines but i also want horizontal black lines.
Please help me out , suggest me some solution.
I have a problem with grid view layout on Android. I can't find solution to eliminate extra space in grid view.I mention the code fro gridview as below :-
<?xml version="1.0" encoding="utf-8"?>
<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:alwaysDrawnWithCache="true"
android:background="#android:color/background_dark"
android:clipChildren="true"
android:columnWidth="100dp"
android:gravity="center_horizontal"
android:horizontalSpacing="2dp"
android:numColumns="auto_fit"
android:padding="0dp"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp" />
now my application's grid view look like this
As shown there is extra space which i want to remove it and it can look like this:-
So please provide me solution..
Thanks in advance..
You need to alter the value for android:columnWidth attribute for all layout types [hdpi,mdpi,xhdpi etc.] supported by your application.
You can use :
android:listSelector="#null"
to eliminate extera space
and try this , for 3 column cell:
android:numColumn = "3"
I have two questions.
The first, when i load the activity first item of gallery is in the middle. How to ask android to align it to left? (actually i used align="left" but it seems doesn't work)
the second, my activity includes three items, header, body and footer. currently the footer (gallery) is on top of body. I want bottom of body stays on above of footer instead of behind of footer.
any suggestions appreciated. The image is like this.
the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:background = "#drawable/bg" >
<!-- Loading header of this UI which is coded separately -->
<include
android:id="#+id/header"
layout="#layout/header_bar" />
<GridView
android:id="#+id/news_gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:numColumns="2"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:layout_below="#id/header"
android:layout_centerInParent="true" />
<Gallery
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
For 1st:
Check this existing SO question:
android gallery image position problem
For 2nd:
- You need to include android:layout_above="#+id/gallery" in your GridView.
- Remoev android:layout_centerInParent="true"
In short, define:
<GridView
android:id="#+id/news_gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dip"
android:numColumns="2"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:layout_below="#+id/header"
android:layout_above="#+id/gallery"/>
I'm new on Android and I have a silly problem with my application design.
My problem is that I want to make a grid as shown in this example http://developer.android.com/guide/tutorials/views/hello-gridview.html
but I want to create a texbox below the grid and a button after the grid. The textbox has to be always at the top and the button always at the bottom. I have done this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView1"
android:layout_marginLeft="20px"
android:text="#string/intro"
android:layout_marginTop="20px"
android:textSize="35px">
</TextView>
<GridView
android:id="#+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
</GridView>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Button_create"
android:textSize="18px">
android:id="#+id/button1">
</Button>
</LinearLayout>
But with this code I have the textbox at the top but not the button at the bottom always. It appears when the grid finish. Also I noticed that in the example there're 2 o 3 columns inside the grid as I want but with this code it only appears one and I do not know why.
Could you help me?
PS. For who will edit the code zone, could you explain me what I have to put when a line ends but it continues the code? Thanks and sorry for your time editing my post
You should put an android:layout_gravity value of e.g. 1 to the GridView which you have determined to fill the height of the parent and then for the Button, put value of 0.5.