Reputation:
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
inside ScrollView
image given to me is not fit in UI layout. So I am thinking I convert a ScrollView
to ImageView
. Is there any procedure in android.
Plz help me.
Upvotes: 4
Views: 13343
Reputation: 1597
I found a nice solution, in your ImageView parameters, just add -
android:adjustViewBounds="true"
Upvotes: 17
Reputation: 49
I find a very easy solution, all you need to do is add
android:src="@drawable/hayhouse"
to your imageview in layout xml file.
Upvotes: -3
Reputation: 3053
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);
Hope it helps
Upvotes: 1
Reputation: 3966
Try this:
<?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>
Hope this helps.
Upvotes: 3
Reputation: 135
<ScrollView>
<RelativeLayout>
<ImageView/>
</RelativeLayout>
</ScrollView>
This will work for you
Upvotes: -2
Reputation: 1372
hello I think you can solve your problem like this
<anyLayout>
<ScrollView>
<RelativeLayout>
<ImageView/>
</RelativeLayout>
</ScrollView>
</anyLayout>
scroll view work within a layout.
Upvotes: -2