如何使SetImagresource动态

时间:2018-08-01 20:49:40

标签: android android-studio

我正在使用滑动库将sqlite数据库中的图像路径转换为imageview中的expendablelistview。现在,我想使这些图片可缩放,因此我使用了photoview库。 。我遇到的问题是,调用photoView.setImageRessource时只能选择一张要显示的图片。我怎样才能适应每次不同图片的缩放(取决于从URL单击的内容)

这是我的代码:

case R.id.child3 :
    ImageView url = (ImageView) view;
    String urls;
    urls = cursor.getString(cursor.getColumnIndex(Database.DATABASE_CHILD_3));
    Glide.with(MainActivity.this).load(urls).into(url);
    url.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
            View mView = getLayoutInflater().inflate(R.layout.dialog_custom_layout, null);
            PhotoView photoView = mView.findViewById(R.id.imageView);
            photoView.setImageResource(R.drawable.anatomy);
            mBuilder.setView(mView);
            AlertDialog mDialog = mBuilder.create();
            mDialog.show();
        }
    });
    break;

1 个答案:

答案 0 :(得分:0)

改为使用 setImageDrawable()

 url.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
                    View mView = getLayoutInflater().inflate(R.layout.dialog_custom_layout, null);
                    PhotoView photoView = mView.findViewById(R.id.imageView);
                    photoView.setImageDrawable(((ImageView)view).getDrawable());
                    mBuilder.setView(mView);
                    AlertDialog mDialog = mBuilder.create();
                    mDialog.show();
                }
            });