I'm loading images dynamically from the Android Camera folder into a horizontal scroll view. The problem is that the scroll view has a huge space at the end of it (right side), as well as the images are being pushed off the screen in the front as I'm populating the scroll view (to the left). The more images being loaded in, the larger the gap at the end of the scroll view and the more images are being pushed off the front.
The xml is just a scroll view as the parent, and a linear layout as the child.
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal" >
<LinearLayout
android:id="@+id/imageList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
The code is using an asynctask to load the images in.
private class loadImages extends AsyncTask<Context, ImageView, Boolean> {
@Override
protected Boolean doInBackground(Context... params) {
File sdCard = Environment.getExternalStorageDirectory();
dir = new File(sdCard.getAbsolutePath() + "/DCIM/Camera");
dir.mkdirs();
ImageView gtbImage = null;
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
File imageLocation = new File(dir.getAbsolutePath() + "/" + children[i]);
Bitmap myBitmap = decodeFile(imageLocation, 250, 250);
gtbImage = new ImageView(getApplicationContext());
gtbImage.setImageBitmap(myBitmap);
imageList = (LinearLayout) findViewById(R.id.imageList);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.RIGHT);
p.setMargins(5, 5, 5, 5);
gtbImage.setLayoutParams(p);
gtbImage.setPadding(1, 1, 1, 1);
gtbImage.setBackgroundColor(Color.WHITE);
gtbImage.setScaleType(ImageView.ScaleType.FIT_CENTER);
publishProgress(gtbImage);
}
}
return null;
}
protected void onProgressUpdate(ImageView... v) {
imageList.addView(v[0]);
}
Here is an image to better describe what the end of the scrollview looks like. Take note of the big blank spot at the end. The more images, the bigger that space grows.
Very baffled by this, I'm sure its something simple that I'm missing but after researching over and over again, I've hit a dead end and need a set of wiser eyes to take a look :)