zoukankan      html  css  js  c++  java
  • 每日总结-android读取assets文件

     1         listTemplet = getTempletFileList();
     2         for (int i = 0; i < listTemplet.size(); i++) {
     3             final ImageView imageView = new ImageView(this);
     4             imageView.setLayoutParams(new LayoutParams(100, 100));
     5             imageView.setScaleType(ScaleType.CENTER_CROP);
     6             imageView.setPadding(10, 1, 0, 1);
     7             imageView.setId(i);
     8             InputStream bitmap = null;
     9             try {
    10                 bitmap = getAssets().open("templet/"+listTemplet.get(i));
    11             } catch (IOException e) {
    12                 e.printStackTrace();
    13             }
    14             Bitmap bm = BitmapFactory.decodeStream(bitmap);
    15             imageView.setImageBitmap(bm);
    16             imageView.setClickable(true);
    17             imageView.setOnClickListener(new OnClickListener() {
    18                 
    19                 @Override
    20                 public void onClick(View v) {
    21                     //TODO 模板点击事件
    22 //                    Toast.makeText(MainActivity.this, "点击了..."+imageView.getId(), Toast.LENGTH_SHORT).show();
    23                     showToast("点击了..."+imageView.getId());
    24                     templetId = imageView.getId();
    25                 }
    26             });
     1     private ArrayList<String> getTempletFileList() {
     2         String[] templetNames = null;
     3         try {
     4             AssetManager am = getAssets();
     5             templetNames = am.list("templet");
     6             for (String string : templetNames) {
     7                 listTemplet.add(string);
     8             }
     9         } catch (IOException e) {
    10             e.printStackTrace();
    11         }
    12         return listTemplet;
    13     }

    每天坚持总结,总会发生质变!

  • 相关阅读:
    Assembly之instruction之CMP
    Assembly之Instruction之Byte and Word
    MSP430之section(1)
    MSP430之software development flow
    openMSP430之Custom linker script
    CDC之Synchronizers
    CDC之Metastability
    Embedded之Stack之三
    Embedded之Stack之二
    Embedded之Stack之一
  • 原文地址:https://www.cnblogs.com/dongye/p/3975218.html
Copyright © 2011-2022 走看看