2013-07-07 2 views
0

자산 폴더에서 가져온 이미지로 HorizontalScrollview를 수행하려고합니다. 외부 저장소에서 이미지를 가져 오는 예제로 작업 중이며 자산 폴더 경로를 변경해야하는 이유가 무엇인지 알지 못합니다. 자산을 읽기이미지를 가져올 경로를 변경하십시오.

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

답변

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 

} 
관련 문제