80,359
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="utf-8"?>
<TabHost android:id="@+id/maintabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="vertical">
<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"></LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab2"></LinearLayout>
</FrameLayout>
<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs"
android:layout_alignParentBottom="true"></TabWidget>
</RelativeLayout>
</TabHost>
<?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="40dp"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:background="@drawable/icon">
<TextView android:id="@+id/tab_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textColor="#000000"
android:textStyle="bold"
android:background="@drawable/icon"/>
</RelativeLayout>
package com.test.t1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class Test1 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabmain);
TabHost tabHost = (TabHost) findViewById(R.id.maintabhost);
tabHost.setup();
//tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("p1").setContent(R.id.tab1));
//tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("p2").setContent(R.id.tab2));
Intent intent1 = new Intent(this, ListV.class);
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("p1").setContent(intent1));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("p2").setContent(intent1));
}
}
package com.test.t1;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;
public class ListV extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getListView().setCacheColorHint(0);
this.getListView().setBackgroundColor(android.graphics.Color.WHITE);
SimpleAdapter adapter = new SimpleAdapter(this,getData(),R.layout.main,new String[]{"title","info"}, new int[]{1,2});
setListAdapter(adapter);
}
private List<Map<String, Object>> getData() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map = new HashMap<String, Object>();
map.put("title", "L1");
map.put("info", "1111111111111111111111111111");
list.add(map);
map = new HashMap<String, Object>();
map.put("title", "L2");
map.put("info", "22222222");
list.add(map);
return list;
}
}
//tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("p1").setContent(R.id.tab1)); //tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("p2").setContent(R.id.tab2));
Intent intent1 = new Intent(this, ListV.class); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("p1").setContent(intent1)); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("p2").setContent(intent1));