Android: cartoon APP development notes read images from Assets locally

Source: Internet
Author: User

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


 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.