我使用Glide库将图像加载到imageView中,我不知道如何使图像捏到可缩放

Tow*_*lie 9 java android imageview android-glide

public class MainActivity extends AppCompatActivity {

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


    //Variables
    ImageView imageView;
    imageView = (ImageView) findViewById(R.id.imageView);

    //Loading into ImageView
    Glide.with(this)
            .load("http://vrijeme.hr/bradar.gif")
            .into(imageView);
}
Run Code Online (Sandbox Code Playgroud)

我也试过使用Picasso,然后将它连接到PhotoView库,但它没有做任何事情,当我尝试捏缩放它根本没有放大时,这是该代码的一部分:

ImageView imageView;
PhotoViewAttacher photoView;

imageView = (ImageView) findViewById(R.id.imageView);
photoView = new PhotoViewAttacher(imageView);
Picasso.with(this)
       .load("link")
       .resize(1080,80)
       .into(imageView);
Run Code Online (Sandbox Code Playgroud)

Ric*_*Dam 7

这个库在这里PhotoView很受欢迎。
https://github.com/chrisbanes/PhotoView

它拥有13,500颗星,有30多个贡献者支持它,如此之多的人在使用它,以及将其集成到项目中有多么容易,这几乎就像是一种标准。

也与Glide^。^ 兼容


安装chrisbanes的官方文档)

将其添加到您的根build.gradle文件(而不是模块build.gradle文件)中:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后,将该库添加到您的模块中 build.gradle

dependencies {
    implementation 'com.github.chrisbanes:PhotoView:latest.release.here'
}
Run Code Online (Sandbox Code Playgroud)

在撰写本文时,latest.release.here2.1.4


用法chrisbanes的官方文档)

提供了一个示例,该示例显示了如何以更高级的方式使用该库,但是为了完整起见,这是使PhotoView工作所需的全部条件:

<com.github.chrisbanes.photoview.PhotoView
    android:id="@+id/photo_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)
PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
photoView.setImageResource(R.drawable.image);
Run Code Online (Sandbox Code Playgroud)

而已!


Glide搭配使用

没有什么改变!!

PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
Glide.with(this).load(imageUrl).into(photoView);
Run Code Online (Sandbox Code Playgroud)

  • 也许是广告,但至少它与 Glide 配合得很好。好的。 (3认同)

K.O*_*.Os 5

例如,您可以使用此库. https://github.com/MikeOrtiz/TouchImageView

将图像加载到此窗口小部件中,而不是ImageView

样品用法:

private TouchImageView mContentView;
private private SimpleTarget target;

mContentView = (TouchImageView) findViewById(R.id.fullscreen_content);

target = new SimpleTarget<Bitmap>() {
        @Override
   public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) 
{
            // do something with the bitmap
            // for demonstration purposes, let's just set it to an ImageView
            mContentView.setImageBitmap(bitmap);
        }
    };



    Glide.with(this) // could be an issue!
            .load( imagePath )
            .asBitmap()
            .into(target);
Run Code Online (Sandbox Code Playgroud)

请注意,我也首先使用SimpleTarget,对于大图像使用Glide和pinch缩放效果是一种很好的做法.

布局将是这样的:

<FrameLayout 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"
tools:context="com.example.FullscreenActivity">


<com.yourPath.TouchImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/fullscreen_content"/>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

此外,有时在此设置后加载图像存在问题.对我来说是这样的.我从TouchImageView类重写方法:

@Override
public void setImageBitmap(Bitmap bm) {
    imageRenderedAtLeastOnce = false;
    super.setImageBitmap(bm);
    savePreviousImageValues();
    fitImageToView();
}
Run Code Online (Sandbox Code Playgroud)