madu243
madu243

Reputation: 233

Load image without cropping in imageview android

I created the app to display images in carousel view. I loaded images into imageview which is in another xml layout file & set them in carousel view contain in main xml layout file.

Here how i load imaged into image view

public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.showsmain, null);
        ImageView image=(ImageView)vi.findViewById(R.id.imageView1);
        //LinearLayout rlayout=(LinearLayout)vi.findViewById(R.id.layout);
       image.setImageResource(R.drawable.black);
        orgWidth = image.getDrawable().getIntrinsicWidth();
        orgHeight = image.getDrawable().getIntrinsicHeight();
        imageLoader.DisplayImage(data[position], image);
        imageLoader.getDimension(widthScreen, heightScreen);

        LinearLayout lhome=(LinearLayout)((Activity) activity).findViewById(R.id.layouthome);
//        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
//              widthScreen,heightScreen/3);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    widthScreen,heightScreen/3);
        params.width=orgWidth;
            image.setLayoutParams(params);
            image.setScaleType(ImageView.ScaleType.FIT_XY);

        return vi;
    }

orgWidth is a width of imageview. widthscreen is a width of screen where app is run. below you can see how image is loaded in carousel view.

![enter image description here][1]

here you see image is crop. I want to load the images without crop....

I try to handle this during three days with three question in stackoverflow. If anyone can know the answer .....help me

here I also give my carousel layout xml file....

<com.touchmenotapps.carousel.simple.HorizontalCarouselLayout
        android:id="@+id/carousel_layout_event"
        android:layout_width="600dp"
        android:layout_height="500dp"
        android:layout_above="@+id/relativeLayout1"
        android:layout_alignTop="@+id/carousel_layout" >
    </com.touchmenotapps.carousel.simple.HorizontalCarouselLayout>

Upvotes: 0

Views: 2856

Answers (1)

npace
npace

Reputation: 4258

After you make your ImageView, call this:

image.setScaleType(ScaleType.CENTER_INSIDE);

Then, instead of cropping, your image will scale to fit the View bounds with a maintained aspect ratio.

Upvotes: 3

Related Questions