Error during post inflation process for TabHost - java

I have a FrameLayout inside of a TabHost. I am getting the following error. How can I get it to render in Eclipse?
Error during post inflation process:
The FrameLayout for the TabHost has no content. Rendering failed.
Here is my XML
<?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">
<!--
<RelativeLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="#+id/actionbarRelativeLayout">
<ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="#drawable/icon" android:id="#+id/stocktwitsImageButton"></ImageButton>
<ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="#drawable/icon" android:id="#+id/composeImageButton" android:layout_alignParentRight="true"></ImageButton>
</RelativeLayout>
-->
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<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"
android:padding="5dp" />
</LinearLayout>
</TabHost>

This is extract from Android's source setupTabHost method:
final int count = content.getChildCount();
if (count == 0) {
throw new PostInflateException(
"The FrameLayout for the TabHost has no content. Rendering failed.\n");
}
As the exception says, you need to have content. Refactor the XML to:
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tab1"></LinearLayout>
</FrameLayout>

Related

Multiple LinearLayout in ScrollView

I'm stucked trying to insert multiple LinearLayout or FrameLayout (whatever..) in a ScrollView.
My structure is:
Activity
...FragmentA
...FragmentB
...FragmentC
activity_layout.xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/container_main"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/border"
android:orientation="horizontal"/>
<LinearLayout
android:id="#+id/container_gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/border"
android:orientation="horizontal"/>
<LinearLayout
android:id="#+id/container_video"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/border"
android:orientation="horizontal"/>
</LinearLayout>
One of my Fragments for example, has this layout:
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.arbiec.conex.activities.MainActivity" />
The problem!!
I can only see the 2 first fragments.
BUT when i hardcode the layout_height of the LinearLayout in my main layout (The one from the Activity) then it works just fine! But i dont want to hardcode it, because i do not know how much space will it take, it should be dynamic with wrap_content.
Any ideas?? Why could this be?
Thanks!
Try this code...
Set below property in Scrollview
android:fillViewport="true"
Try this modified layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="#+id/container_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border"
/>
<FrameLayout
android:id="#+id/container_gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border"
/>
<FrameLayout
android:id="#+id/container_video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border"
/>
</LinearLayout>
</ScrollView>
Hope this help!

GridView row spacing fills screen

Im having a grid view that has blank space between two rows. I'm trying to remove the white space but without success. So can anyone tell me how can I remove the white spacing?
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="#android:color/white"
android:orientation="vertical" >
<GridView
android:id="#+id/bg_chooser_grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numColumns="auto_fit"/>
</LinearLayout>
here is gridItem xml:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/grid_item_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:scaleType="centerInside"
android:src="#drawable/ic_launcher" />
The "important part of the adapter":
gridImg = (ImageView) vi.findViewById(R.id.grid_item_img);
gridImg.setImageResource(data.get(position));
And here is how it looks:
Try This Code :-
<GridView
android:id="#+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:columnWidth="90dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>
and customGridAdapter xml view:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#drawable/grid_border"
android:orientation="vertical"
android:padding="5dp" >
<ImageView
android:id="#+id/item_image"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_gravity="center"
android:layout_margin="10dp"
android:scaleType="fitXY"
android:src="#drawable/home" >
</ImageView>
</LinearLayout>
This image use in LinearLayout android:background="#drawable/grid_border"

FragmentTabHost with viewpager issue in layout

I have just implemented Tabs with swipe using FragmentTabHost in android. But there's an issue in the layout. When i running my application i get the below output. The swipe is only work for the below part
I Want something like
The code of XML i'm using is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>

adview on every tab (tabhost, admob)

Im trying to get the Google Ads adview on every tab of my tabhost, but its not working.
If I place the adview in the main.xml, I can see the adview on every tab.
But the problem then is that the views (buttons) are showing above the adview, so I cant see the ad anymore?
Main.xml:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<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" >
<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" >
<include layout="#layout/tab1" />
<include layout="#layout/tab2" />
<include layout="#layout/tab3" />
<include layout="#layout/tab4" />
</FrameLayout>
</LinearLayout>
</TabHost>
</TableLayout>
</LinearLayout>
tab1.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res/com.this.app"
android:id="#+id/tab1"
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"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="xxx" />
<ScrollView
android:id="#+id/scrollview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/adView" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableRow>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Lets try this layout.It is always below the frame layout.Hope it helps.
<?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"
android:background="#fff" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/tv"
android:layout_below="#android:id/tabs" >
</FrameLayout>
<TextView
android:id="#+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Ads" />
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#android:id/tabcontent"
android:layout_alignParentTop="true"
android:paddingTop="-10dip" >
</TabWidget>
</RelativeLayout>
</TabHost>

TabHost/TabWidget views not centering in parent

Have a TabHost that doesn't center the views even though I set the views layout_gravity to center_horizontal. Here is my XML, the button is all I've added to the tab1 layout so far.
<?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"
>
<TabHost android:id="#+id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:id="#+id/linearLayout1" android:layout_height="fill_parent" android:orientation="vertical">
<TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#android:id/tabcontent">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab1">
<Button android:layout_width="wrap_content" android:id="#+id/button1" android:layout_gravity="center_horizontal" android:text="Button" android:layout_height="wrap_content"></Button>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab2"></LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab3"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
you have to set gravity at the parent!
Try setting the android:gravity attribute on the parent of the button instead.
Like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="#+id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:id="#+id/linearLayout1" android:layout_height="fill_parent" android:orientation="vertical">
<TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#android:id/tabcontent">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab1" android:gravity="center_horizontal">
<Button android:layout_width="wrap_content" android:id="#+id/button1" android:text="Button" android:layout_height="wrap_content"></Button>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab2"></LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/tab3"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost></LinearLayout>

Categories