ImageView dentro de un ScrollView

I am working on a android project. I n that I have to deal with ScrollViews to scroll image. But when I am using ImageView dentro ScrollView image given to me is not fit in UI layout. So I am thinking I convert a ScrollView a ImageView. Is there any procedure in android. Plz help me.

preguntado el 02 de febrero de 12 a las 10:02

6 Respuestas

I found a nice solution, in your ImageView parameters, just add -

android:adjustViewBounds="true"

Respondido 19 Abr '13, 00:04

Prueba esto:

<?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:src="@drawable/ic_launcher" 
                android:contentDescription="@string/describe_something_here"/>

        </RelativeLayout>

    </ScrollView>

Espero que esto ayude.

Respondido 02 Feb 12, 15:02

If you want to fit your imageview inside your emulator screen then why to use scrollview. You can scale your imageview inside your emulator screen like this

 LinearLayout linLayout = new LinearLayout(this);

        // load the origial BitMap (500 x 500 px)
        Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
               R.drawable.android);

        int width = bitmapOrg.width();
        int height = bitmapOrg.height();
        int newWidth = 200;
        int newHeight = 200;

        // calculate the scale - in this case = 0.4f
        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;

        // createa matrix for the manipulation
        Matrix matrix = new Matrix();
        // resize the bit map
        matrix.postScale(scaleWidth, scaleHeight);
        // rotate the Bitmap
        matrix.postRotate(45);

        // recreate the new Bitmap
        Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
                          width, height, matrix, true);

        // make a Drawable from Bitmap to allow to set the BitMap
        // to the ImageView, ImageButton or what ever
        BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

        ImageView imageView = new ImageView(this);

        // set the Drawable on the ImageView
        imageView.setImageDrawable(bmd);

        // center the Image
        imageView.setScaleType(ScaleType.CENTER);

        // add ImageView to the Layout
        linLayout.addView(imageView,
                new LinearLayout.LayoutParams(
                      LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT
                )
        );

        // set LinearLayout as ContentView
        setContentView(linLayout);

Espero eso ayude

Respondido 02 Feb 12, 15:02

thanks for reply. but i am working on project it is requirement to use scroll view because firtehr it is going to be in use - user1184851

so plz tell me convenient way. - user1184851

hello I think you can solve your problem like this

<anyLayout>
   <ScrollView>
        <RelativeLayout>

            <ImageView/>

         </RelativeLayout>

   </ScrollView>

</anyLayout>

scroll view work within a layout.

Respondido 02 Feb 12, 14:02

I use the same above but my image resolution is going beyound the screen of screen.but i have to make that fully fit to screen of emulator.so i try to ise android:background property.and in .java file i try to convert a scroll view to image view. if is there any method plz tell me.thanks in advance - user1184851

<ScrollView>
        <RelativeLayout>

            <ImageView/>

         </RelativeLayout>

   </ScrollView>

Esto funcionará para ti

Respondido 02 Feb 12, 14:02

based on ur previous comment dont set image in xml use setbackgroundresource in class file - Donald

I find a very easy solution, all you need to do is add

android:src="@drawable/hayhouse"

to your imageview in layout xml file.

Respondido 09 Abr '13, 08:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.