
I am working on an application where i have to use android tabhost. I am facing a problem using it, as layout of my activity does not show up properly under the tab. The layout of the activity shows up only in the upper half of the emulator screen and bottom half remain black, while when i saw its xml in design view it depicts the required design.
xml is added below as myscreen.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/gray"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="@+id/button_twitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/twitter_login_unpressed" />
<ImageView
android:id="@+id/button_separator"
android:layout_width="wrap_content"
android:layout_height="30px"
android:background="@color/gray" />
<ImageView
android:id="@+id/button_facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/facebook_login_unpressed" />
</LinearLayout>
and the relevant activity just contains the following code in onCreate:
protected void onCreate(Bundle savedInstanceState) {
Log.e("Now", "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.myscreen);
}
i am unable to figure out why the whole layout under the tab is not shown properly, and tabActivity just has and intent to this activity, there is nothing complex in there…It contains the following code:
public class InfoTabActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.infotablayout);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, myActivity.class);
spec = tabHost.newTabSpec("settings").setIndicator("", res.getDrawable(R.drawable.today_unpressed)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
What can possibly be the problem? Any help is appreciated.
infotablayout.xml contains this 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="wrap_content"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="45px" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
The problem is most likely in your
infotablayout.xml– theFrameLayoutyou use forTabContentmost likely has the attributelayout_height="wrap_content". (Maybe you could post that xml-file too, so we can have a look).Edit
The
LinearLayoutthat holds yourTabWidgetand theFrameLayouthas its height set towrap_contentwhich is why your layout wraps.Little off topic, but you should be able to reduce your
myscreen.xmlfile to the following: