Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically add ImageView in LinearLayout without extra spaces?

I am trying to add ImageView programatically inside a LinearLayout, which has vertical orientation. My layout file is describe as the xml below:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:paddingTop="5dip"
   android:id="@+id/mainView"">

   <TextView android:id="@+id/tvTituloInformacao"
    android:layout_width="fill_parent"          
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:textStyle="bold"
    android:textColor="@color/white"
    android:gravity="center_horizontal"
    android:shadowColor="@color/black_translucent"
    android:shadowDx="2.0"
    android:shadowDy="2.0"
    android:shadowRadius="3.0"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true" /> 

    <LinearLayout android:id="@+id/resourceContainer"
    android:layout_width="fill_parent"          
    android:layout_height="wrap_content"
    android:layout_marginTop="5dip"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="10dip"
    android:layout_marginBottom="10dip"
    android:padding="3dip"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    android:layout_below="@+id/tvTituloInformacao"
    android:background="@color/black_translucent2" /> 

 </RelativeLayout>

And my java source code that adds the ImageViews to the LinearLayout is as follow:

for(Resource r : mUser.getPictures()) {
    ImageView img = new ImageView(this);
    img.setVisibility(View.VISIBLE);
    img.setTag(r.getThumb60());
    imageLoader.DisplayImage(r.getThumb60(), this, img);
    ((LinearLayout) tempFotosView.findViewById(R.id.resourceContainer)).addView(img);
}

What happens is that before and after each ImageView I am getting some extra spaces that should not be there, so the height of the images container increases a lot. One test that I did and got the expected result was not to use the imageLoader and instead I set the ImageResource programatically to a static image file. This way I didn't get any extra space.

The weird result is illustrated in the image below:

enter image description here

Is there a way to not add this extra space?

like image 591
Thiago Avatar asked Nov 14 '22 12:11

Thiago


1 Answers

I think images you are loading in image views may have some extra spacing on top and bottom, and other assumption you are loading images in imageview, with different resolution than your screen-size, and setting scaleType of ImageView to centerInside, if it is the case please try using following by fixing height of the image view as well, and set scaleType to fixXY.

like image 77
jeet Avatar answered Nov 16 '22 04:11

jeet