Admob and ListActivity - android

I have asked this question before but didn't get a "good enough" answer.
My problem basically is that I can't get Admob to show correctly in a ListActivity.
My layout looks like this:
<?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"
xmlns:myapp="http://schemas.android.com/apk/res/se.javalia.myDrinks"
android:orientation="vertical">
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<ListView android:id="#+id/android:list" android:layout_alignParentTop="true"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<TextView android:id="#+id/android:empty"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="#string/main_no_items" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" >
<com.admob.android.ads.AdView android:id="#+id/ad"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent" android:layout_height="wrap_content"
myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
myapp:keywords="drink alcohol wiskey rum soda" myapp:refreshInterval="300" />
</LinearLayout>
</RelativeLayout>
The problem right now is that if I change the layout_hight to fill_parent or attempt a value larger than 150 px the ad wont show. With a layout_hight of 150 or less it shows nicely. The goal is to get the list to fill the screen after the ad has taken its place.
Any suggestions? I'm quite lost about how to solve this.
I will update the question if the answer didn't get all the way so please check for updates.
Thanks in advance
Roland

Use one RelativeLayout as the outer wrapper and set your listview to parent top and your adview to parent bottom.

I had this problem and was very difficult to find answers in internet. But i had luck, and I found an answer that worked for me.
Please remove in your code android:layout_height="wrap_content" and add these two new lines into your Listview
android:layout_height="0dip"
android:layout_weight="1"
Your Listview code should look like this
<ListView
android:id="#+id/android:list"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
I hope that works for you.

Related

TouchListview with fixed footer

My question should be answered here: Fixed footer not displaying the bottom-most list item
But it does not work for me.
I want a listview with a fixed footer at the bottom. At the moment, the listview is as large as the window, which makes the footer overlap. XML:
<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!-- <ImageView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:src="#drawable/baby_blue_solid" android:scaleType="centerCrop" />-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footer_cloud"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_alignParentBottom="true"
>
<ImageView android:id="#+id/add_icon"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_add"
/>
<ImageView android:id="#+id/cloudBG"
android:layout_centerInParent="true"
android:layout_width="230dp"
android:layout_height="60dp"
android:background="#drawable/cl"
/>
<ImageView
android:id="#+id/footer_divider"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#android:drawable/divider_horizontal_bright"
android:layout_above="#id/cloudBG"
/>
</RelativeLayout>
<com.commonsware.cwac.tlv.TouchListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tlv="http://schemas.android.com/apk/res/com.commonsware.cwac.tlv.demo"
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/root"
android_layout_above="#id/footer_cloud"
android:drawSelectorOnTop="false"
android:listSelector="#android:color/transparent"
tlv:normal_height="64dip"
tlv:grabber="#+id/icon"
tlv:remove_mode="slideLeft"
/>
</RelativeLayout>
Although Im using a touchlistview by Commonsware, that shouldn't be a reason why it wouldn't work, I think. Can anyone spot the mistake?
Also, I can't see the divider I implemented. Both when I use the background or src attribute, no effect is visible.
First, fall back to a simpler widget when diagnosing problems whenever possible. If you are seeing oddities with TouchListView, try a regular ListView.
Second, your layout rules for the TouchListView are strange. You are trying to make the widget below its own container. And, you should be using 0dp for the height.
Try those things. If the problem is still occurring and is unique to TouchListView, I will need a sample project the reproduces the error to investigate further. If the problem occurs with regular ListView, and what I have written here has not helped, your next step is to use Hierarchy View to try to diagnose what is wrong with your layout.

Unable to populate listview with custom rows when component is above listview

I'm having issues with a ListView using custom rows that are loaded from a database.
If, for the list screen, I place a button above the ListView, no visible rows appear in the listview.
However as soon as I remove the button, everything works fine. I want the button (or any other component) to appear above to make it more user friendly. Attached are the two code samples below.
This is the XML file of the ListView Activity that works:
<?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="#color/real_red_dark">
<LinearLayout
android:id="#+id/llMain"
android:layout_height="fill_parent"
android:background="#drawable/real_background"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:gravity="center">
<ListView
android:id="#+android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/llButton"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/no_sessions"
android:textStyle="bold"
android:textSize="18dp"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
However, if I have the Button added above it, it will not show whatsoever:
<?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="#color/real_red_dark">
<LinearLayout
android:id="#+id/llMain"
android:layout_height="fill_parent"
android:background="#drawable/real_background"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:gravity="center">
<Button
android:id="#+id/btnSearch"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:layout_gravity="center_horizontal"
android:layout_marginTop="3dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:text="Find Sessions"
android:textStyle="bold" />
<ListView
android:id="#+android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/llButton"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/no_sessions"
android:textStyle="bold"
android:textSize="18dp"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
You could try adding the button programmatically as a header view in the listview itself, rather than in the xml layout.
use listView.addHeaderView(View)
http://developer.android.com/reference/android/widget/ListView.html#addHeaderView(android.view.View)
It is better if you use RelativeLayout than LinearLayout,it is also recommended by the android docs.Try to use android:layout_height value as "wrap_content" for ListView and TextView(which you may use to indicate for empty rows),it may help to you.
Something which doesn't look right but I'm assuming it's just a typo in the above...
android:id="#+android:id/list"
...there shouldn't be a + between # and android:. Using #+ is for adding a new resource id of your own, i.e., #+id:. You're also doing the same thing for the TextView...
android:id="#+android:id/empty"
Another thing but not sure it's relevant is you're specifying...
android:layout_below="#+id/llButton"
...I doubt it's the problem as android:layout_below isn't valid for a LinearLayout (it's for RelativeLayout) but there isn't a Button with the id of llButton in your layout. If there was, the + would also be incorrect as you should be specifying an existing id.
Not sure if amending the above would fix things but it could just be that the layout inflation is coming out 'wrong' due to those issues.

Problem with the display of custom listview (webview in my listview)

I am having an issue that make me crazy
I have a listview with WebView inside. So I created a custom listview.
The WebView forbid me to click so I created a webviewclicklistener.
My problem was that when I display some images, my webviews are "shaking" as if it wants to load the image a thousand times.
In fact I discovered that the height size of some elements change like every seconds, that give a feeling of shake.
The only way I found to fix it is to give a layout:height value for my listview.
My new problem is that when I put for exemple 600dip, I have a scrollbar, but I can't look at the end of my listviews.
If I put like 1000dip, I don't have scroll bar and I can't see the end of my list neither.
Here is my layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#drawable/woodbackground"
android:layout_weight="1">
<TextView android:background="#android:color/transparent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="Question" android:textSize="30px"></TextView>
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<WebView android:id="#+id/wvplquestion" android:layout_height="wrap_content"
android:layout_width="fill_parent"></WebView>
</ScrollView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/transparent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical"
android:layout_weight="1">
<TextView android:background="#android:color/transparent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="Select Answer" android:textSize="30px"></TextView>
<ListView android:id="#+id/lvquestion" android:layout_width="fill_parent"
android:layout_height="600dip" android:prompt="#string/selectp" />
</LinearLayout>
And my custom listview layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:padding="3dip">
<WebView android:id="#+id/weblistview" android:layout_width="fill_parent"
android:layout_height="wrap_content"></WebView>
Thanks for your help
maybe you can try to change your listview layout height. Instead of wrap content, put a fixed height. I don't know if it will be working, but you can try it. I'd a problem similar to yours and I solved it like this.
I hope it will work. Good luck ;)
Seems it mostly happens when several webviews contained into one scrollview. Seems at least first webviews should have fixed height.

Android - Layout gravity/width related problem

I know i am doing a small mistake.
I am using LinearLayout and i want to place the "icon-image" at "Center".
I am using the following code:
<LinearLayout
android:id="#+id/LinearLayout01"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0">
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
android:layout_gravity="center_vertical|center_horizontal|center">
</ImageView>
</LinearLayout>
<LinearLayout>
............
</LinearLayout>
</LinearLayout>
As you see above, i have also set layout_gravity.
Now my problem is, if i set android:layout_width="wrap_context" instead of "fill_parent" in Child Linear Layout (i.e. LinearLayout02) then it works fine. but then whats should i do to set icon-image at Center while setting fill_parent?
Pls anybody focus their knowledge and let me help to find out the mistake.
Pls help me.
Thanx,
Paresh
Add this to LinearLayout02 to specify that its contents should be centered horizontally:
android:gravity="center_horizontal"

Layout :How to get the bottom bar under listview

I hope can get the layout like this:
-----Search bar(EditTextview)---
-----Listview(Rows)--------
-----Bottom bar(Contain many buttons)---
Pls give many samples
Thanks very much
I paste my xml file here.Pls help me check it:
Here's a layout from one of my apps, should be enough to get you started:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/list_view"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_weight="0"
android:gravity="bottom">
<!-- Buttons go here -->
</LinearLayout>
</LinearLayout>
Search for layout_weight to get an idea of how it works.
within your linearlayout, use Relativelayout for each edittext,listview and footer.
in footer layout set android:orientation="horizontal" it works.

Categories

Resources