Android Implementation Gallery Click to zoom in

Source: Internet
Author: User

Picture enlargement idea:
First, you can transform the image through the Matrix object, zoom in when you choose, and zoom out to the original size when you lose focus.


Double scale = 1.2;
int width = bm.getwidth ();
int height = bm.getheight ();
LOG.I ("Size:", width+ "");
float ScaleWidth = (float) (scale*width);
float ScaleHeight = (float) (scale*height);
LOG.I ("Size:", scalewidth+ "");
Matrix matrix = new Matrix ();
Matrix.postscale (ScaleWidth, ScaleHeight);
BM = BITMAP.CREATEBITMAP (BM, 0, 0, width, height, matrix, true);

Second, through the animation

<?xml version= "1.0" encoding= "Utf-8"?>

<scale
Xmlns:android= "Http://schemas.android.com/apk/res/android"

Android:interpolator= "@android: Anim/decelerate_interpolator"

android:fromxscale= "1"
Android:toxscale= "1.1"
android:fromyscale= "1"
Android:toyscale= "1.1"

android:pivotx= "50%"
Android:pivoty= "50%"
Android:duration= ">"

</scale>

Thirdly, through setlayoutparams

View.setlayoutparams (New Gallery.layoutparams (150,150));
int mcounts = G.getcount ()-1;
if (position>0 && (Position < mcounts)) {
G.getchildat (position-1). Setlayoutparams (New Gallery.layoutparams (136, 88));
G.getchildat (position + 1). Setlayoutparams (New Gallery.layoutparams (136, 88));
}
if (position = = 0) {
G.getchildat (position + 1). Setlayoutparams (New Gallery.layoutparams (136, 88));
}
if (position = = mcounts) {
G.getchildat (position-1). Setlayoutparams (New Gallery.layoutparams (136, 88));
}

Note: where (136, 88) is the size of the picture in gallery, it is set inside the Imageadapter. (150,150) is the size of the selected image enlarged, can be arbitrarily set, as long as the difference with (136, 88) on the line, is to observe the change, I set the 150 just.

Iv. by combining animations and Layoutparam

Gallery.setonitemselectedlistener (New Onitemselectedlistener () {
@Override
Public
void onitemselected (adapterview<?> arg0, View arg1,
int arg2, long arg3) {
ImageView v = (ImageView) arg1;
if (Tempview! = null && v.hashcode ()! = Tempview.hashcode ()) {
Tempview.setlayoutparams (New Gallery.layoutparams (50,50));
}
V.startanimation (Tolarge);
Tempview = v;
V.setlayoutparams (New Gallery.layoutparams (60,60));
//
V.setlayoutparams (New Gallery.layoutparams (130,130));
Tvname.settext (Templist.get (arg2). Getpicname ());
}
@Override
Public
void onnothingselected (adapterview<?> arg0) {
Tvname.settext ("nothing selected.");
}
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.