<?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">
<TextView
     android:id="@+id/pn_county" android:layout_width="0.6in" android:layout_height="0.25in" 
     android:text="国        家" android:textSize="18px"  
     android:gravity="center"
    ></TextView>
    
    <Spinner
    android:id="@+id/pn_county_select"  
     android:layout_width="fill_parent" android:layout_toRightOf="@id/pn_county"
     android:layout_height="0.26in"  android:layout_marginTop="0.01in"
></Spinner>  
<TextView
android:id="@+id/pn_mnc_label" android:text="运营商列表"
android:layout_below="@id/pn_county"
android:layout_width="0.6in"
android:layout_height="wrap_content"
android:textSize="18px"
android:textStyle="bold"
></TextView>
<Spinner
    android:id="@+id/pn_mnc_list"    android:layout_below="@id/pn_county_select"
     android:layout_width="fill_parent" android:layout_toRightOf="@id/pn_mnc_label"
     android:layout_height="0.26in"  android:layout_marginTop="0.01in"
></Spinner> 
<LinearLayout android:id="@+id/listLinearLayout"//我想在这个位置显示listview列表
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<ListView android:id="@id/android:list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:drawSelectorOnTop="false"
   android:scrollbars="horizontal"/>
</LinearLayout>
</LinearLayout>
这是listview(表格)的布局文件
<TableLayout android:id="@+id/tableLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TableRow android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:id="@+id/listview">
<TextView 
android:layout_width="80dip"
android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"
android:id="@+id/a07_ls_txtYF"></TextView>
<TextView 
android:layout_width="80dip"
android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"
android:id="@+id/a07_ls_txtXXSR"></TextView>
<TextView
android:layout_width="80dip" 
android:layout_height="wrap_content"
android:textColor="#42AF40"
    android:drawableRight="@drawable/line_y"
android:id="@+id/a07_ls_txtYNSE"></TextView>
<TextView
android:layout_width="80dip"
android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"
android:id="@+id/a07_ls_txtSNSE"></TextView>
<TextView
android:layout_width="80dip"
android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"
android:id="@+id/a07_ls_txtSNSRE"></TextView>
<TextView
android:layout_width="80dip" 
android:layout_height="wrap_content"
android:textColor="#42AF40"
    android:drawableRight="@drawable/line_y"
android:id="@+id/a07_ls_txt01"></TextView>
<TextView
android:layout_width="80dip"
android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"
android:id="@+id/a07_ls_txt02"></TextView>
<TextView
android:layout_width="80dip"
android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"
android:id="@+id/a07_ls_txt03"></TextView>
<TextView
android:layout_width="80dip" 
android:layout_height="wrap_content"
android:textColor="#42AF40"
    android:drawableRight="@drawable/line_y"
android:id="@+id/a07_ls_txt04"></TextView>
<TextView
android:layout_width="80dip"
android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"
android:id="@+id/a07_ls_txt05"></TextView>

</TableRow>
</TableLayout>
下面是listView的java代码public class TableList extends Activity {
private ListView lv; /** Called when the activity is first created. */
String name[]={"周旋","于世龙","于翠","杨涛","覃达","周旋","于世龙"};
String course[]={"语文","数学","英语","历史","政治","语文","数学"};
String score[]={"100","90","30","50","90","100","90"};
String id[]={"10123","10124","10125","10126","10127","10123","10125"};
String py[]={"良好","良好","一般","良好","良好","良好","很好"};
String name1[]={"周旋","于世龙","于翠","杨涛","覃达","周旋","widm"};
String course2[]={"语文","数学","英语","历史","政治","语文","数学"};
String score3[]={"100","90","30","50","90","100","90"};
String py1[]={"良好","良好","一般","良好","良好","良好","很好"};
String score4[]={"100","90","30","50","90","100","90"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xml);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < name.length; i++) {
HashMap<String, String> map1 = new HashMap<String, String>();
map1.put("Name", name[i]);
map1.put("ID", id[i]);
map1.put("Course", course[i]);
map1.put("Score", score[i]);
map1.put("PY", py[i]);
map1.put("Name1", name1[i]);
map1.put("Course2", course2[i]);
map1.put("Score3", score3[i]);
map1.put("Score4", score4[i]);
map1.put("PY1", py1[i]);
mylist.add(map1);
} SpecialAdapter adapter = new SpecialAdapter(this, mylist,
R.layout.main, new String[] {"PY", "Course", "Score",
"ID", "Name" ,"Name1","Course","Score3","Score4","PY1"}, new int[] 
                              {R.id.a07_ls_txtSNSRE, R.id.a07_ls_txtYNSE,        R.id.a07_ls_txtSNSE,R.id.a07_ls_txtXXSR,R.id.a07_ls_txtYF,R.id.a07_ls_txt01,
R.id.a07_ls_txt02,R.id.a07_ls_txt03 ,R.id.a07_ls_txt04,R.id.a07_ls_txt05});

TextView t1 = new TextView(this);
t1.setText("标题");
t1.setBackgroundResource(R.drawable.bk);
TextView t2 = new TextView(this);
t2.setText("标题");
t2.setBackgroundResource(R.drawable.bk);
TextView t3 = new TextView(this);
t3.setText("标题");
t3.setBackgroundResource(R.drawable.bk);
TextView t4 = new TextView(this);
t4.setText("标题");
t4.setBackgroundResource(R.drawable.bk);
TextView t5 = new TextView(this);
t5.setText("标题");
t5.setBackgroundResource(R.drawable.bk);
TextView t6 = new TextView(this);
t6.setText("标题");
t6.setBackgroundResource(R.drawable.bk);
TextView t7 = new TextView(this);
t7.setText("标题");
t7.setBackgroundResource(R.drawable.bk);
TextView t8 = new TextView(this);
t8.setText("标题");
t8.setBackgroundResource(R.drawable.bk);
TextView t9 = new TextView(this);
t9.setText("标题");
t9.setBackgroundResource(R.drawable.bk);
TextView t10 = new TextView(this);
t10.setText("标题");
t10.setBackgroundResource(R.drawable.bk);

LinearLayout linear = new LinearLayout(this);
linear.setBackgroundResource(R.drawable.bg_comment_grey);
linear.addView(t1, 79, 45);
linear.addView(t2, 80, 45);
linear.addView(t3, 80, 45);
linear.addView(t4, 80, 45);
linear.addView(t5, 80, 45);
linear.addView(t6, 80, 45);
linear.addView(t7, 80, 45);
linear.addView(t8, 80, 45);
linear.addView(t9, 80, 45);
linear.addView(t10, 80, 45);
lv = new ListView(this);
lv.setHorizontalScrollBarEnabled(true);
lv.addHeaderView(linear);// 设置listHeader 始终位于列表顶部
lv.setAdapter(adapter);

HorizontalScrollView hsv = new HorizontalScrollView(this);
hsv.addView(lv);
setContentView(hsv);

// lv = (ListView)findViewById(R.layout.main);
// lv.setHorizontalScrollBarEnabled(true);
// lv.setSelector(R.drawable.bg_setting_tablerow);
// lv.setAdapter(adapter);
// setContentView(lv);


}
}class SpecialAdapter extends SimpleAdapter {
private int[] colors = new int[] { 0x30FF0000, 0x300000FF }; public SpecialAdapter(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.length;
if (colorPos == 1) {
view.setBackgroundColor(Color.argb(250, 255, 255, 255));
} else {
view.setBackgroundColor(Color.argb(250, 224, 243, 250));
}
return view;
}
}

解决方案 »

  1.   

    你在activity里获取listView,然后写个适配器就行了!
      

  2.   


    您能详细的指点一下吗,我刚接触android对这些东西还不了解
      

  3.   

    LZ最好说的详细点,现在是ListView显示得有问题还是怎么回事
      

  4.   

    LZ,listview不是要把所有的item都写在resource中的,一般是通过adaptor设置,只在resource中写item的layout就可以了,所有的item都使用这个layout。
      

  5.   

    用ActivityGroup将实现ListView的那个Activity嵌入到MainActivity进去。
      

  6.   

    用ActivityGroup将实现ListView的那个Activity嵌入到MainActivity