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);
}
}