开发者

Android Gallery issue - gallery size is bigger than expected

开发者 https://www.devze.com 2023-03-04 21:33 出处:网络
I\'ve got Activity with gallery widget alongside w开发者_JAVA百科ith other views. I want gallery to be as wide as my Activity is, and I want my image to match gallery size. I\'m a little bit confused

I've got Activity with gallery widget alongside w开发者_JAVA百科ith other views. I want gallery to be as wide as my Activity is, and I want my image to match gallery size. I'm a little bit confused with ImageView.ScaleType, but that's what I've chosen:

Part of my curtom adapter for Gallery:

@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"
     />

Android Gallery issue - gallery size is bigger than expected

What I need is to get rid of that extra grey part of gallery on top and bottom(marked red). I wonder, why does it have such size? Maybe I do something funny with that scaling type stuff?


Try using ScaleType.CENTER_CROP instead - this will make the image fit the full height while maintaining it's aspect ratio - ie some of the image on the left and right will not be visible.

Alternatively you could use ScaleType.FIT_XY - this will not maintain the aspect ratio and will stretch the image so that all of the image fits inside the ImageView.


Try changing the layout params of the image view (set the height to fill_parent as well) -

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


android:layout_weight="1" for gridview or parent. you must use "hierarchyviewer" tools for better undestand what layout need to have design priority, for undestand what layout don't fill own parent.

I hope that it help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号