I have a tab layout like this:
------------------
------------------
{1}----[2]-----[3]
Code:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_weight="1"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginBottom="-4dp"/>
</LinearLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/topLayout"
android:layout_gravity="bottom"
>
<!-- Ad Placeholder -->
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="MYID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
android:layout_gravity="top"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
/>
</RelativeLayout>
</TabHost>
My 3 tabs are on the bottom. However my ad overlaps them, is there a way to put the ad right underneath the tabs?
Check out this example from AdMob's Ad Catalog sample application. It involves wrapping the TabHost and ad around a RelativeLayout, aligning the ad to the bottom, and the TabHost above the ad.
You may want to take a deeper look at the sample application - it has other working examples on how to use AdMob in various layouts.
Related
I am trying to get an AdView directly below a TabHost. RelativeLayout does allow this to happen with android:layout_alignParentBottom="true" however this overlaps TabHost contents, and does so for the ScrollView's I add inside each Tab (this would probably occur for any views whose height was large enough)
Right now the closest I can get to having a TabHost and AdView in their own seperate space on the screen is using this code (below), that allows me to have a Ad directly above the TabHost...so close, any ideas?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="####"
ads:loadAdOnCreate="true"
ads:testDevices="####" />
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
</LinearLayout>
You should make the tab host to fill the remaining space after the adview like
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0">
Now the tab host will take the remaining space after the adview.
I have a layout which contains a Tabhost. The tabs are at the bottom of the screen. The first tab starts an ActivityGroup. The first activity in that ActivityGroup contains a scrollview. When the contents are displayed in the scrollview and you scroll all the way down, the bottom of the scrollview is hidden behind the tabs. Any ideas how to fix this?
When I start the activitygroup, I use this code:
Window window = getLocalActivityManager().startActivity(pActivityClass.getName(), intent);
setContentView(window.getDecorView());
Is the decor view the entire screen? I just want the view to be the tabcontent.
Here is the main layout:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignParentTop="true"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</TabHost>
Here is the view I want in the tabcontent:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout android:id="#+id/myLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"/>
... a bunch of other components ...
</RelativeLayout>
</ScrollView>
Fix your layout so the content view fits above the tab widget, instead of filling the entire parent container, which tells it to lay out as the full size of the RelativeLayout and then lay the TabWidget on top. Something more like this:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#android:id/tabs"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</TabHost>
I also removed some of the unnecessary items like android:orientation which does nothing inside of a RelativeLayout.
HTH
Optimal result.
android:minWidth= Increase the value of...
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget
**android:minWidth="480dp"**
android:id="#android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TabWidget>
</HorizontalScrollView>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#android:id/tabs"/>
Here, the key line is,
android:layout_above="#android:id/tabs"
I know there might be a "correct" way to do this, but I just added
<LinearLayout android:layout_width="fill_parent"
android:layout_height="50dp"></LinearLayout>
to the bottom of the xml file I was loading into the tab.
Also user1060374 is right the FrameLayout needs to be above the Tabwidget or the scrollview will hide(be on top of) the tabbar if the contents needs scrolled.
But just doing this won't answer your question, so I added the padding.
Hey folks
I managed to implement Admob into a normal linear layout so far.
Now I added a additional scrollview and the adbanner disappeared. I don´t know what I can do against it.
Follows the code from the .xml where I added the scrollview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="match_parent">
<ScrollView android:id="#+id/scrollView1" android:layout_height="wrap_content" android:layout_width="match_parent">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
[whole bunch of layout elements whoch shouldn´t affect the adbanner]
</LinearLayout>
</ScrollView>
In my linear layout ,where the adbanner still works, the whole adbanner position was done in the main activitiy.java file (did this with help of the tutorial at taiic.com)
// Lookup R.layout.main
LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
String pubID = "xxxxxxxxxxxxxxxxxx";
AdView adView = new AdView(this, AdSize.BANNER, pubID);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
Can anybody tell me what to change or what code to add when implementing an admob banner into a scrollview?
edit:
i tried to add
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapprimaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
android:alignParentBottom="true"/>
between last two lines in the .xml
</LinearLayout>
[here]
</ScrollView>
but then im getting the error "error: Error parsing XML: unbound prefix"
cheers
About the parsing error:
Is this a typo in the question? myapprimaryTextColor="#FFFFFF" instead of myapp:primaryTextColor="#FFFFFF" . This would give you the xml parse error.
About the layouts:
Use a RelativeLayout. The working code is at the end of the post. First, some theory :)
Your ScrollView is taking the whole screen, that's why you don't see the admob view. When the scrollview is defined, all the screen is availabel to it, so it takes it. The admob view is actually drawn below your screen. It can be reproduced in this example:
non-working layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView android:id="#+id/scrollView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test1"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test2"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test3"
/>
</LinearLayout>
</ScrollView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test4"
/>
</LinearLayout>
If you use a RelativeLayout instead, you can set it up so the admob is aligned to the bottom of the screen, and the scrollview above it, taking the rest of the available space.
working layout
<?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">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test4"
android:id="#+id/test4"
android:layout_alignParentBottom="true"
/>
<ScrollView android:id="#+id/scrollView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_above="#id/test4"
>
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test1"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test2"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test3"
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I used the admob xml version and that is what I use and it works. The ad is at the top. Just copy and paste and you will be scrolling along shortly.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res/com.yourproject.here"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a14dc1c9d6xxxxx"
ads:adSize="BANNER" />
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
[whole bunch of layout elements whoch shouldn´t affect the adbanner]
</ScrollView>
</LinearLayout>
I have a screen that uses tabs in my android application. There is a line (like a border) that shows between the tabwidget and the framelayout. I want to get rid of that line, but cant seem to find what it is. I have determined that it is part of the FrameLayout by setting its visibilty to gone. Please refer to the code below:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fb8c10"
>
<ImageView
android:id="#+id/img_confirm_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/confirm_header"
/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0dip"
android:background="#fb8c10"
android:tabStripEnabled="false"
/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/tab_bg"
/>
</LinearLayout>
</TabHost>
This is a link of the current layout and what I'm trying to do
http://img441.imageshack.us/g/screenshot20110116at513.png/
The orange layout is my app, and the gray is what I'm trying to do.
Notice how in the gray screenshot the tab flows into the frame.
Apologies for the links, I can't post images yet :p
Thanks!
I managed to solve this by manipulating the z-index using relative layout. I was able to position the tabs slightly over the frame layout. Refer to code below:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fb8c10"
>
<ImageView
android:id="#+id/img_confirm_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/tab_header"
/>
<RelativeLayout
android:id="#+id/widget77"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
android:layout_marginTop="33dip"
/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fb8c10"
android:tabStripEnabled="true"
android:layout_above="#android:id/tabcontent"
android:layout_marginBottom="40dip"
/>
</RelativeLayout>
</LinearLayout>
</TabHost>
Just now I came across this issue. However, I also tried to remove the top border of FrameLayout. I did it. but I don't think it is a way to remove the top border. anyway FYI,
Just place an TextView with background white on Border and use AbsoluteLayout.
Eg:
<AbsoluteLayout>
<TabHost
android:layout_x="0dip"
android:layout_y="5dip" ...>
<AbsoluteLayout android:padding="5dip" android:background="#ffffff">
<TabWidget/>
<FrameLayout ....
android:layout_x="0dip" android:layout_y="65dip" />
</AbsoluteLayout>
</TabHost>
<TextView
android:layout_width="fill_parent" android:layout_height="25dip"
android:layout_x="0dip" android:layout_y="65dip"
android:background="#ffffff"/>
</AbsoluteLayout>
My ads don't display at all, I think I've followed the documentation correctly but they still won't show. The program is basically a webview and I want the ad to display at the bottom.
Heres my layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/man.utd.headlines"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC" />
</LinearLayout>
Any ideas?
EDIT: this is what I now have but it still doesn't appear to be quite right:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/man.utd.headlines"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC" />
<WebView
android:id="#+id/webview"
android:layout_above="#id/ad"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
Your Problem is that the WebView will take all the space on the screen and there is no space left for the ads.
A LinearLayout will distribute the space on a first come first serve rule. If the first View takes all the space the second view won't get any space..
I would use a RelativeLayout and add the adds first with a layout_alignParentBottom attribute and then add the webview with a layout_above="id for the adds". This will ensure that the adds are always on the bottom of the screen even if the webview wont take all the space at the moment and the webview will always be above the adds.
I had the same problem, i fixed it this way:
LinearLayout as main layout, inside it linearLayout(for the ad) and a webview, set wrap_content on the linearlayout for the ad, so, it will first show an ad and then the rest of the screen will be the webview.
example of mine:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/addmob"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></LinearLayout>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent" android:id="#+id/rltvLayout1"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/linearLayoutwebview"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:orientation="vertical">
<WebView android:id="#+id/webView1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fitsSystemWindows="true" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:id="#+id/ad_layout" android:layout_height="wrap_content"
android:gravity="bottom" android:layout_alignParentBottom="true"
android:layout_alignBottom="#+id/home_layout">
<com.google.ads.AdView android:layout_width="wrap_content"
android:layout_height="wrap_content" ads:adUnitId="put here your ID"
ads:adSize="BANNER" android:id="#+id/adView" ads:refreshInterval="60" />
</LinearLayout>
</RelativeLayout>