Android: cartoon APP development notes read images from Assets locally
List is the directory name under Assets.
// Read private ArrayList locally
GetImageFromAssetsFile (String list) {String test = list; ArrayList
Newpiclistinfo = new ArrayList
(); String [] list_image = null; try {// obtain the file names of all files in the assets/list/directory, so that list_image = this can be used for subsequent operations. getAssets (). list (list);} catch (IOException e1) {// TODO Auto-generated catch block e1.printStackTrace () ;}for (int I = 0; I
PicListAdapter. java
Package com. cartoon. adapters; import java. util. arrayList; import com. cartoon. r; import android. content. context; import android. view. layoutInflater; import android. view. view; import android. view. view. measureSpec; import android. view. viewGroup; import android. view. viewGroup. marginLayoutParams; import android. view. windowManager; import android. widget. arrayAdapter; import android. widget. imageView; import android. widget. listAdapter; import android. widget. listView; import android. widget. relativeLayout; import android. widget. textView; public class PicListAdapter extends ArrayAdapter
{Public PicListAdapter (Context context, int textViewResourceId, ArrayList
Objects) {super (context, textViewResourceId, objects) ;}@ Overridepublic View getView (int position, View convertView, ViewGroup parent) {ViewHolder holder = null; View view View; windowManager wm = (WindowManager) getContext (). getSystemService (Context. WINDOW_SERVICE); int width = wm. getdefadisplay display (). getWidth (); int height = wm. getdefadisplay display (). getHeight (); if (convertView = null) {view = LayoutInflater. From (getContext ()). inflate (R. layout. piclist_item, null); holder = new ViewHolder (); holder. piclist_item = (ImageView) view. findViewById (R. id. piclist_item); // sets the position of the image ViewGroup. layoutParams margin = new ViewGroup. layoutParams (holder. piclist_item.getLayoutParams (); RelativeLayout. layoutParams layoutParams = new RelativeLayout. layoutParams (margin); layoutParams. height = (int) (width * 0.5677); // you can specify the Image height. LayoutParams. width = width; // set the width of the image layoutParams. setMargins (15, 0, 15, 0); holder. piclist_item.setLayoutParams (layoutParams); holder. piclist_item.setScaleType (ImageView. scaleType. FIT_START); view. setTag (holder);} else {view = convertView; holder = (ViewHolder) convertView. getTag ();} final PicListInfo singleoder = getItem (position); if (singleoder! = Null) {holder. piclist_item.setImageBitmap (singleoder. getPicUrl ();} return view;} public class ViewHolder {public ImageView piclist_item ;}}
PicListInfo. java
Package com. cartoon. adapters; import android. graphics. bitmap; public class PicListInfo {private Bitmap PicUrl; // image address // The get and set methods of the above attributes are as follows: public Bitmap getPicUrl () {return PicUrl ;} public void setPicUrl (Bitmap picUrl) {PicUrl = picUrl ;}}