0

アセットフォルダーから取得した画像で Horizo​​ntalScrollview を実行しようとしています。外部ストレージから画像を取得する例を使用していますが、アセットフォルダーへのパスを変更する必要があるかわかりません。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    myGallery = (LinearLayout)findViewById(R.id.mygallery);

    String ExternalStorageDirectoryPath = Environment
      .getExternalStorageDirectory()
      .getAbsolutePath();

    String targetPath = ExternalStorageDirectoryPath + "/test/";

    Toast.makeText(getApplicationContext(), targetPath, Toast.LENGTH_LONG).show();
    File targetDirector = new File(targetPath);

    File[] files = targetDirector.listFiles();
    for (File file : files){
         myGallery.addView(insertPhoto(file.getAbsolutePath()));
    }    
}
4

1 に答える 1

0

アセットの読み取りは非常に簡単です。

単一の写真:

AssetManager assetManager = getResources().getAssets();
InputStream is = assetManager.open("photo.jpeg");

写真のリスト:

AssetManager  assetManager = getResources().getAssets();
String[] files =  assetManager.list("");
for(String f: files){
    File photo = new File(f); //or
    InputStream is = assetManager.open(f);
    //do something with the photo

}
于 2013-07-07T12:53:22.250 に答える