---
title: "ScrollView下面ListView下拉條顯示有問題"
author: "ltwoini"
date: "2010-07-23T15:24:06Z"
tags: []
categories: ["编程语言"]
slug: "scrollview-listview"
draft: false
lastmod: "2010-07-23T15:25:19Z"
id: 719797
url: "https://ltwoini.iteye.com/blog/719797"
---

ScrollView 與ListView的下來條都顯示,而且ListView內容顯示比較丑.google后有個方法是:

先動態生成其他的view 然后listview.addHeaderView(View header),這樣子可以實現.

實踐一下,ok.代碼如下:

**Querstion:要是一個ScrollView下有多個ListView該么辦呢?**

protected void onCreate(Bundle savedInstanceState) {  
  super.onCreate(savedInstanceState);  
  //生成頭  
  View header=LayoutInflater.from(this).inflate(R.layout.appitem, null);  
  header.setFocusable(false);  
  this.getListView().addHeaderView(header);//加頭  
//  this.setContentView(R.layout.appitem);  
//  LinearLayout tr = (LinearLayout) header.findViewById(R.id.appitem\_llout);  
  this.getListView().setBackgroundColor(Color.argb(150, 22, 70, 150));//設置背景色  
  String appname = null;  
  if (null != this.getIntent()) {  
   appname = this.getIntent().getStringExtra("appId");  
  }  
  App item = AppDataManage.findAppByAppId(appname);  
  if(null !=item){  
   //begin add by eric 2009/07/23  
   fileSize = (TextView)header.findViewById(R.id.appitem\_fileSize);  
   fileSize.setText(SingleApplication.nfcstore  
     .getResources().getString(R.string.fileSize)+":"+item.getAppSize() +" "+ item.getAppSizeUnit());  
   version = (TextView)header.findViewById(R.id.appitem\_version);  
   version.setText(SingleApplication.nfcstore  
     .getResources().getString(R.string.version)+":"+item.getVersion());  
   languageEnvironment = (TextView) header.findViewById(R.id.appitem\_lanuguage);  
   languageEnvironment.setText(SingleApplication.nfcstore  
     .getResources().getString(R.string.language)+":"+item.getLanguageEnvironment());  
   runEnvironment = (TextView) header.findViewById(R.id.appitem\_runenv);  
   languageEnvironment.setText(SingleApplication.nfcstore  
     .getResources().getString(R.string.run\_env)+":"+item.getRunEnvironment());  
   description = (TextView)header.findViewById(R.id.appitem\_description);  
   description.setText(item.getDescription()==null?"無":item.getDescription());  
   authorEmail = (TextView)header.findViewById(R.id.appitem\_devloperEmail);  
   authorEmail.setText(item.getAuthorEmail());  
   //end by eric 2009/07/23  
   appName = (TextView) header.findViewById(R.id.appitem\_appName);  
   author =(TextView)header.findViewById(R.id.appitem\_author);  
   downloadNum =(TextView)header.findViewById(R.id.appitem\_downloadNum);  
   uploadTime =(TextView)header.findViewById(R.id.appitem\_uploadTime);  
   price =(TextView)header.findViewById(R.id.appitem\_price);  
   grade = (RatingBar) header.findViewById(R.id.appitem\_ratingBar);  
   imgv = (ImageView) header.findViewById(R.id.appitem\_img);  
   imgv.setImageDrawable(header.getResources().getDrawable(AppDataManage.findImageId(item.getImageUrl())));  
     
   appName.setText(item.getAppName());  
   author.setText(item.getAuthor());  
   downloadNum.setText(AppDataManage.DOWNLOAD+item.getDownloadNum());  
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");  
   uploadTime.setText(AppDataManage.UPLOAD\_TIME+sdf.format(item.getUploadTime()));  
   grade.setNumStars(5);  
   grade.setRating(item.getGrade());  
   Log.d("AppItemActivity","ratingbar grade:"+item.getGrade());  
   if(item.isFree())  
    price.setText("免費");  
   else  
    price.setText(item.getUnit()+" "+item.getCharge());  
   GROUP\_FREE\_MENU\_VISIBLE = (!item.isInstalled()) && item.isFree();  
   GROUP\_CHARGE\_MENU\_VISIBLE = (!item.isInstalled()) && (!item.isFree());  
   GROUP\_INSTALLED\_MENU\_VISIBLE = item.isInstalled();  
   gallery = (Gallery) header.findViewById(R.id.appitem\_gallery);  
   gallery.setAdapter(new ImageAdapter(this));  
   AppCommentAdapter cmadapter = new AppCommentAdapter(this);  
   cmadapter.setMData(AppDataManage.getCommentData(item));  
   this.setListAdapter(cmadapter);  
  }  
 }