【问题标题】:How to fetch image URL from Fresco's SimpleDraweeView?如何从 Fresco 的 SimpleDraweeView 中获取图像 URL?
【发布时间】:2019-05-02 06:04:48
【问题描述】:

Fresco SimpleDraweeView 获取图像 URL。

我有带有 EditText 和 SimpleDraweeView 的 recyclerView 项目,在我的活动按钮上也有。单击按钮时,我想将整个 recyclerview 项目数据放入 ArrayList。

这是在按钮单击时编写的代码,我成功获得了除 SimpleDraweeView URL 之外的 editText 数据。

        ArrayList<ContactUs> getContactUsArrayList = new ArrayList<>();
    for (int i = 0; i < getContactUsArrayList.size(); i++) {
        View view = rvContact.getChildAt(i);
        EditText etName = (EditText) view.findViewById(R.id.etName);
        EditText etMobile = (EditText) view.findViewById(R.id.etMobile);
        SimpleDraweeView sdvImage = (SimpleDraweeView) view.findViewById(R.id.sdvImage);

        String strName = etName.getText().toString();
        String strNumber = etMobile.getText().toString();
        String strImgUrl = ""; //what is the property?


    }

从 SimpleDraweeView 获取 URL 的属性是什么?

【问题讨论】:

  • 你是如何在 recyclerview 中推送数据的?
  • 从 API 加载数据并将数据推送到适配器,然后我尝试从活动中单击按钮获取整个项目数据
  • 您可以从 API 中保存 url,并在 for 循环中使用相同的索引号。目前,SimpleDraweeView 不支持直接 url。
  • 好吧,这意味着,根据位置获取特定项目数据,如果我错了,请纠正我。
  • 是的。将网址保存在另一个列表中并稍后使用

标签: android url fresco imageurl


【解决方案1】:

你必须像这样解析你的图片 URL。

SimpleDraweeView simpleDraweeView = 
(SimpleDraweeView)findViewById(R.id.simpleviewid);

Uri imageuri = Uri.parse("YOUR IMAGE URL");
simpleDraweeView.setImageURI(imageuri);

一定要在setContentView()之前初始化fresco,simpleDraweeView的XML文件中的宽高不能是换行内容。试试这个。

它对我有用。

【讨论】:

    【解决方案2】:

    我理解您的问题,但没有任何属性可以以字符串的形式获取图像,但您可以通过以下方式实现此目的。我假设您是否正确设置了布局中的图像。

    Drawable drawable = draweeView.getBackground();
            Bitmap bitmap = draweeView.getDrawingCache();
            Drawable drawable1 = draweeView.getHierarchy().getTopLevelDrawable();
    

    希望对你有帮助。

    【讨论】:

    • 正如我在上面看到的 cmets 您应该保存加载数据列表或您在适配器中传递的列表以在回收视图中加载数据,您可以使用相同的列表来获取图片 url 根据 onBindViewHolder 方法中的位置。
    【解决方案3】:

    我得到了基于 Answers 和 cmets 的解决方案

    我做了什么

    替换此代码

            ArrayList<ContactUs> getContactUsArrayList = new ArrayList<>();
        for (int i = 0; i < getContactUsArrayList.size(); i++) {
            View view = rvContact.getChildAt(i);
            EditText etName = (EditText) view.findViewById(R.id.etName);
            EditText etMobile = (EditText) view.findViewById(R.id.etMobile);
            SimpleDraweeView sdvImage = (SimpleDraweeView) view.findViewById(R.id.sdvImage);
    
            String strName = etName.getText().toString();
            String strNumber = etMobile.getText().toString();
            String strImgUrl = ""; //what is the property?
    
    
        }
    

    使用此代码

       ArrayList<ContactUs> getContactUsArrayList = new ArrayList<>();
        ContactUs contactUs;
        for (int i = 0; i < getContactUsArrayList.size(); i++) {
            contactUs = getContactUsArrayList.get(i);//Here i got whole object.
            String strName = contactUs.getUserName();
            String strNumber = contactUs.getUserMobile();
            String strImgUrl=contactUs.getImagePath();
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 2020-01-18
      相关资源
      最近更新 更多