Problem with Android Gallery - gallery size is larger than expected

I have an Activity with gallery widget along with other views. I want the gallery to be as wide as my activity, and I want my image to fit the size of the gallery. I am a bit confused by ImageView.ScaleType , but this is what I selected:

Part of my gallery curtom adapter:

@Override public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView=new ImageView(activity); imageView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); //imageView.setPadding(10, 10, 10, 10); String imageUrl="my_uri.com/sample.png"; imageLoader.displayImage(imageUrl, activity, imageView); imageView.setTag(imageUrl); return imageView; } 

Part of my activity layout:

  <Gallery android:id="@+id/gallery" android:layout_below="@+id/tvDetailedDescription" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#CCCCCC" /> 

enter image description here

I need to get rid of this extra gray part of the gallery above and below (marked in red). I wonder why it has such a size? Maybe I'm doing something funny with this type of scaling type?

+4
source share
3 answers

Try using ScaleType.CENTER_CROP - this will make the image as complete as possible while maintaining its aspect ratio - that is, the part of the image on the left and right will not be visible.

Alternatively, you can use ScaleType.FIT_XY - this will not maintain aspect ratio and stretch the image so that the entire image is inside the ImageView.

+1
source

Try changing the layout settings of the image (set the height and fill_parent) -

 Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
0
source

android: layout_weight = "1" for gridview or parent. you should use the hierarchyviewer tools to better understand which layout should have design priority, for undestand which layout your own parent does not fill.

I hope this helps you.

0
source

All Articles