Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: tabactivity - content of all tabs gets overlapped at first
    text
    copied!<p>I was testing TabActivity with a list in each tab. </p> <p>While running the app, the contents of the tabs gets overlapped like this. <img src="https://i.stack.imgur.com/igSt3.png" alt="enter image description here"></p> <p>After i click on the tabs the overlapping gets cleared. Here is my code :</p> <p>testtabs.xml layout :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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"&gt; &lt;LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;ListView android:id="@+id/list1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"&gt; &lt;/ListView&gt; &lt;ListView android:id="@+id/list2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"&gt; &lt;/ListView&gt; &lt;/FrameLayout&gt; &lt;/LinearLayout&gt; &lt;/TabHost&gt; </code></pre> <p>And Test Activity</p> <pre><code>public class TabbedActivity extends TabActivity { private static final String LIST1_TAB_TAG = "List1"; private static final String LIST2_TAB_TAG = "List2"; private ListView listView1; private ListView listView2; private TabHost tabHost; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.testtabs); tabHost = getTabHost(); // setup list view 1 listView1 = (ListView) findViewById(R.id.list1); // create some dummy strings to add to the list List&lt;String&gt; list1Strings = new ArrayList&lt;String&gt;(); list1Strings.add("List 11"); list1Strings.add("List 12"); list1Strings.add("List 13"); list1Strings.add("List 14"); listView1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, list1Strings)); // setup list view 2 listView2 = (ListView) findViewById(R.id.list2); List&lt;String&gt; list2Strings = new ArrayList&lt;String&gt;(); list2Strings.add("Test2 List 21"); list2Strings.add("Testing 22"); list2Strings.add("More test 23"); list2Strings.add("Test Again 24"); listView2.setAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, list2Strings)); // add views to tab host tabHost.addTab(tabHost.newTabSpec(LIST1_TAB_TAG).setIndicator(LIST1_TAB_TAG).setContent(new TabContentFactory() { public View createTabContent(String arg0) { return listView1; } })); tabHost.addTab(tabHost.newTabSpec(LIST2_TAB_TAG).setIndicator(LIST2_TAB_TAG).setContent(new TabContentFactory() { public View createTabContent(String arg0) { return listView2; } })); tabHost.setCurrentTab(0); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload