我有一个网格视图,我想在listview的页脚中添加,因为我希望这个页面应该具有整页滚动功能。
这是我的代码,我用我的网格视图适配器设置我的网格视图,但它在footer.i中显示空白有两个xml,一个用于标题,另一个仅用于网格视图。
GalleryGridViewAdapter
public class GalleryMainActivityGridViewAdapter extends BaseAdapter {
/**
* Description:Declare the UI components.
*/
private Context mContextGridView;
private GallerySmartLazyLoader sl;
ArrayList<HashMap<String, String>> galleryArray;
/**
* This method is use to set object that will control the listview
*
* @param c
* @param resultArray
*
*/
public GalleryMainActivityGridViewAdapter(Context c, ArrayList<HashMap<String,String>>
resultArray) {
mContextGridView = c;
galleryArray = new ArrayList<HashMap<String, String>>();
galleryArray = resultArray;
sl = new GallerySmartLazyLoader(mContextGridView);
}
public int getCount() {
return galleryArray.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
/**
* Description:This method returns a bitmap related to drawable.
*
* @param bitmapUrl
* to set the background on detail page
*
*/
public Bitmap getBitmap(String bitmapUrl) {
URL url;
try {
System.out.println("bitmapUrl :" + " bitmapUrl : " + bitmapUrl);
url = new URL(bitmapUrl);
return BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
// create View for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
View MyView = convertView;
if (convertView == null) {
/* create a new view of our layout and inflate it in the row */
// Inflate the layout
LayoutInflater inflater = (LayoutInflater) mContextGridView.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
MyView = inflater.inflate(R.layout.gallery_main_page_grid_item, null);
// Initialize the UI components
ImageView imgView_Grid_PlayVideo = (ImageView) MyView.findViewById(R.id.imgView_Grid_PlayVideo);
ImageView imgView_Grid_Thumbnail_Gallery = (ImageView) MyView.findViewById(R.id.imgView_Grid_Thumbnail_Gallery);
TextView txtView_Grid_Views_Gallery = (TextView) MyView.findViewById(R.id.txtView_Grid_Views_Gallery);
Typeface txtViewForViews = Typeface.createFromAsset(MyView.getContext().getAssets(), "fonts/arial.ttf");
txtView_Grid_Views_Gallery.setTypeface(txtViewForViews);
TextView txtView_Grid_Name_Gallery = (TextView) MyView.findViewById(R.id.txtView_Grid_Name_Gallery);
Typeface txtViewForName = Typeface.createFromAsset(MyView.getContext().getAssets(), "fonts/arial_bold.ttf");
txtView_Grid_Views_Gallery.setTypeface(txtViewForName);
ImageView imgView_GridItem_Gallery = (ImageView) MyView.findViewById(R.id.imgView_GridItem_Gallery);
// This will set the item coming from API
imgView_Grid_Thumbnail_Gallery.setImageBitmap(getBitmap(galleryArray.get(0).get("publicUrl") + "/11"));
txtView_Grid_Views_Gallery.setText(galleryArray.get(position).get("hits") + " views");
txtView_Grid_Name_Gallery.setText(galleryArray.get(position).get("user_name"));
imgView_GridItem_Gallery.setScaleType(ImageView.ScaleType.FIT_XY);
imgView_GridItem_Gallery.setPadding(0, 0, 0, 0);
String url = galleryArray.get(position).get("thumbUrl") + "/13";
imgView_GridItem_Gallery.setTag(url);
sl.DisplayImage(url, (Activity) mContextGridView, imgView_GridItem_Gallery);
if (galleryArray.get(position).get("filetype").toString().equals("1")) {
imgView_Grid_PlayVideo.setVisibility(View.GONE);
} else {
imgView_Grid_PlayVideo.setVisibility(View.VISIBLE);
}
}
return MyView;
}
}
GallaryLoginMainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallary_login_main_page_list);
data = new ArrayList<ArrayList<HashMap<String, String>>>();
lstGallaryMain = (ListView) findViewById(R.id.lstGallaryMain);
inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
init(this, R.id.main, getIntent());
if (!Connection()) {
Context context = getApplicationContext();
CharSequence text = "Sorry you need an Internet connection! Please try again when the network is available.";
Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
toast.show();
finish();
} else {
/*
*
* This method is used to Show The loading dialog till the data
* loads for main page.
*/
new AsyncTask<Void, Void, Void>() {
protected void onPreExecute() {
loadingDialog = ProgressDialog.show(GallaryLoginMainActivity.this, getResources().getString(R.string.app_name), "Loading...");
}
@Override
protected Void doInBackground(Void... params) {
loadDataFromServer();
return null;
};
protected void onPostExecute(Void result) {
View footerView = inflater.inflate(R.layout.test_media, null);
GalleryMainActivityGridViewAdapter galleryMainActivityGridViewAdapter = new GalleryMainActivityGridViewAdapter(GallaryLoginMainActivity.this,userDataActivity);
GridView gridView = (GridView)footerView.findViewById(R.id.gridview_Gallery);
gridView.setAdapter(galleryMainActivityGridViewAdapter);
lstGallaryMain.addFooterView(gridView);
((GalleryMainActivityGridViewAdapter)(galleryMainActivityGridViewAdapter)).notifyDataSetChanged();
lstGallaryMain.setAdapter(new GalleryCustomAdapterForMainPage<T>(GallaryLoginMainActivity.this, data));
((BaseAdapter)(lstGallaryMain.getAdapter())).notifyDataSetChanged();
lstGallaryMain.addFooterView(gridView);
GallaryLoginMainActivity.this.onContentChanged();
if (loadingDialog != null && loadingDialog.isShowing()) {
loadingDialog.dismiss();
}
};
}.execute();
}
}
答案 0 :(得分:2)
最后我得到了我自己的问题的答案我已经使用android查询库创建了新的适配器,并在我的屏幕上实现了新的网格视图适配器,并在滚动视图中找到了更好的平滑度...
这是我的代码
public class GalleryMainActivityGridViewAdapter extends BaseAdapter {
AQuery listAQ;
Context mContext;
int layoutResourceId;
ArrayList<HashMap<String, String>> dataArray;
public GalleryMainActivityGridViewAdapter(Context context, ArrayList<HashMap<String, String>> resultArray) {
this.mContext = context;
// this.layoutResourceId = layoutId;
this.dataArray = resultArray;
listAQ = new AQuery(mContext);
// aa = new ArrayAdapter<Photo>(mContext, layoutResourceId);
}
public int getCount() {
return dataArray.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return 0;
}
@SuppressWarnings("deprecation")
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.gallery_main_page_grid_item, parent, false);
}
Holder holder = new Holder();
AQuery aq = listAQ.recycle(convertView);
holder.imgView_Grid_Thumbnail_Gallery = (ImageView) convertView.findViewById(R.id.imgView_Grid_Thumbnail_Gallery);
if (holder.imgView_Grid_Thumbnail_Gallery != null) {
aq.id(holder.imgView_Grid_Thumbnail_Gallery.getId()).image(dataArray.get(position).get("thumbUrl") + "/11");
}
holder.txtView_Grid_Name_Gallery = (TextView) convertView.findViewById(R.id.txtView_Grid_Name_Gallery);
if (holder.txtView_Grid_Name_Gallery != null) {
aq.id(holder.txtView_Grid_Name_Gallery.getId()).text(dataArray.get(position).get("user_name"));
Typeface txtViewForName = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/arial_bold.ttf");
holder.txtView_Grid_Name_Gallery.setTypeface(txtViewForName);
}
holder.imgView_GridItem_Gallery = (ImageView) convertView.findViewById(R.id.imgView_GridItem_Gallery);
if (holder.imgView_GridItem_Gallery != null) {
Bitmap cachedImage = aq.getCachedImage(R.drawable.loading);
String publicUrl = dataArray.get(position).get("publicUrl") + "/13";
if (aq.shouldDelay(convertView, parent, publicUrl, 0)) {
aq.id(holder.imgView_GridItem_Gallery.getId()).image(cachedImage, 0.75f);
} else {
aq.id(holder.imgView_GridItem_Gallery.getId()).image(publicUrl, true, true, 0, 0, cachedImage, 0, 0.75f);
}
}
// if (holder.txtView_Grid_Views_Gallery != null) {
//
// }
holder.imgView_Grid_PlayVideo = (ImageView) convertView.findViewById(R.id.imgView_Grid_PlayVideo);
if (holder.imgView_Grid_PlayVideo != null) {
if (dataArray.get(position).get("filetype").toString().equals("1")) {
holder.imgView_Grid_PlayVideo.setVisibility(View.GONE);
} else {
holder.imgView_Grid_PlayVideo.setVisibility(View.VISIBLE);
}
}
return convertView;
}
class Holder {
ImageView imgView_Grid_PlayVideo;
ImageView imgView_Grid_Thumbnail_Gallery;
TextView txtView_Grid_Views_Gallery;
TextView txtView_Grid_Name_Gallery;
ImageView imgView_GridItem_Gallery;
}
}