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


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);
}

我也尝试使用毕加索,然后将其与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);

此处称为PhotoView的库非常受欢迎。
https://github.com/chrisbanes/photoview

拥有13,500多个恒星,30多个贡献者支持它,如此多的人使用它以及整合到项目中的容易程度,几乎感觉就像是标准。

它也与 Glide ^。 ^

兼容

安装(Chrisbanes的官方文档(

在您的root build.gradle file(不是您的模块build.gradle文件(中添加它:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

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

dependencies {
    implementation 'com.github.chrisbanes:PhotoView:latest.release.here'
}

在写作时, latest.release.here2.1.4


用法(Chrisbanes的官方文档(

提供了一个示例,该样本显示了如何以更高级的方式使用库,但是对于完整性,这是使光值工作所需的一切:

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

就是这样!


使用Glide

什么都没有改变!

PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
Glide.with(this).load(imageUrl).into(photoView);

您可以例如使用此库。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);

请注意,我也首先使用SimpleTarget,使用滑行和捏夹来缩小大图像的效果是一个很好的做法。

,布局将是这样的:

<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>

另外,有时在此设置后加载图像存在问题。对我来说,这样的工作。我从TouchImageView类中覆盖了该方法:

@Override
public void setImageBitmap(Bitmap bm) {
    imageRenderedAtLeastOnce = false;
    super.setImageBitmap(bm);
    savePreviousImageValues();
    fitImageToView();
}

相关内容

最新更新