gpt4 book ai didi

Android:tabactivity - 所有选项卡的内容首先重叠

转载 作者:行者123 更新时间:2023-11-29 14:55:39 25 4
gpt4 key购买 nike

我正在测试 TabActivity,每个选项卡中都有一个列表。

在运行应用程序时,选项卡的内容会像这样重叠。 enter image description here

在我单击选项卡后,重叠被清除。这是我的代码:

testtabs.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">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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">
<ListView
android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<ListView
android:id="@+id/list2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
</FrameLayout>
</LinearLayout>
</TabHost>

和测试 Activity

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<String> list1Strings = new ArrayList<String>();
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<String> list2Strings = new ArrayList<String>();
list2Strings.add("Test2 List 21");
list2Strings.add("Testing 22");
list2Strings.add("More test 23");
list2Strings.add("Test Again 24");

listView2.setAdapter(new ArrayAdapter<String>(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);
}
}

最佳答案

您可以从 xml 布局中删除两个 ListView 并仅在 java 代码中创建它们。

例如listView1 = new ListView(this);

一切都会好起来的。

关于Android:tabactivity - 所有选项卡的内容首先重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7524501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com