微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Android的res文件夹中设置字符串路径而不是资源ID

如何解决如何在Android的res文件夹中设置字符串路径而不是资源ID

|| 在我的应用程序中,我使用网格视图。它可以很好地处理从res文件夹中获取的图像。但是我需要从n个网址的网格视图中显示图像。我的问题是如何将字符串路径(url)设置为imageView.setimageResource()。此函数仅采用可绘制残渣。那是我的问题。 我从
http://developer.android.com/guide/tutorials/views/hello-gridview.html
得到代码 码:
  public View getView(int position,View convertView,ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) {  // if it\'s not recycled,initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(85,85));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8,8,8);
    } else {
        imageView = (ImageView) convertView;
    }

    imageView.setimageResource(mThumbIds[position]); **// here i have to give string url**
    return imageView;
}

// references to our images             **// here i have to store image url as string of array**
private Integer[] mThumbIds = {
        R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d
};
    

解决方法

        ImageView具有setImageURI方法,可让您传递URI作为视图的内容。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。