簡體   English   中英

如何在imageview中添加縮放效果

[英]how to add zoom effect in imageview

我想在活動中顯示圖像。 我用imageview成功地制作了它,但是沒有縮放效果。 我無法放大圖片。 現在如何添加此縮放效果。 我的.xml代碼是:

 <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    android:src="@drawable/cat" />

使用lib https://github.com/chrisbanes/PhotoView

在代碼中

ImageView mImageView;
PhotoViewAttacher mAttacher;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Any implementation of ImageView can be used!
mImageView = (ImageView) findViewById(R.id.iv_photo);

// Set the Drawable displayed
Drawable bitmap = getResources().getDrawable(R.drawable.wallpaper);
mImageView.setImageDrawable(bitmap);

// Attach a PhotoViewAttacher, which takes care of all of the zooming functionality.
mAttacher = new PhotoViewAttacher(mImageView);
}


// If you later call    mImageView.setImageDrawable/setImageBitmap/setImageResource/etc then you just need to call
     attacher.update();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM