I have the following scenario:
I am dynamically assigning an image URI to an ImageView, and then dynamically adding this ImageView to a HorizontalView.
The problem is, I don't see these images loaded in the ImageView, inside the HorizontalView.
Here is my code:
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="100dp">
<LinearLayout
android:id="@+id/imageDisplayer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
Here is my code for loading the images:
public void LoadImages(ArrayList<PhotoPath> photos){
LinearLayout layout = (LinearLayout)findViewById(R.id.imageDisplayer);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if (photos != null) {
for (PhotoPath photo : photos) {
Uri photoUri = Uri.parse(photo.getPhotoPath());
params.setMargins(10, 10, 10, 10);
params.gravity = Gravity.NO_GRAVITY;
ImageView imageView = new ImageView(this);
imageView.setImageURI(photoUri);
imageView.setLayoutParams(params);
layout.addView(imageView);
}
}
}
Here is an example of my URI:
content://com.android.providers.media.documents/document/image%3A48
What am I doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…