3

I have a problem with imageswitcher to fit on screen. Please check PIC 1. There is still white free space on the edge of the screen. I want to achieve the effect in PIC 2. There is no empty space and imageswitcher perfect fit to screen. I can do this efect with imageView using:

android:scaleType="centerCrop"

but it looks centerCrop doesn't works with imageSwitcher. Thanks for any idea how to fix it.

UPDATE:

Here is my XML code: I added there android:scaleType="fitXY" but it didn't help.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageSwitcher
        android:id="@+id/imageswitcher"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/it_intro1" >
    </ImageSwitcher>

enter image description here

SOLUTION: finally it helped add this line of code: imageView.setScaleType(ImageView.ScaleType.FIT_XY);

public View makeView() {

            ImageView imageView = new ImageView(Introduction.this);
             imageView.setScaleType(ImageView.ScaleType.FIT_XY);

            LayoutParams params = new ImageSwitcher.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

            imageView.setLayoutParams(params);
            return imageView;

        }
Tetsujin no Oni
  • 7,300
  • 2
  • 29
  • 46
Matwosk
  • 459
  • 1
  • 9
  • 25
  • can you post your layout (xml) ? The problem could be with the parent holding the image, also the right scale type for you is FIT_XY – GhostDerfel Feb 03 '14 at 03:20
  • I tried add there FIT_XY but it didn't help. I updated my question so now u can see XML layout. Can you please take a look on it? Thanks. – Matwosk Feb 03 '14 at 09:48
  • 1
    If you find a solution, you should post here and mark as resolved – GhostDerfel Feb 03 '14 at 12:03

2 Answers2

7

SOLUTION: finally it helped add this line of code: imageView.setScaleType(ImageView.ScaleType.FIT_XY);

public View makeView() {

        ImageView imageView = new ImageView(Introduction.this);
         imageView.setScaleType(ImageView.ScaleType.FIT_XY);

        LayoutParams params = new ImageSwitcher.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

        imageView.setLayoutParams(params);
        return imageView;

    }
Matwosk
  • 459
  • 1
  • 9
  • 25
0

In the imageswitcher's xml, set:

 android:layout_width="match_parent"
 android:scaleType="fitXY"
fida1989
  • 3,234
  • 1
  • 27
  • 30