Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用ImageView创建自定义视图,Asynctask不工作_Java_Android_Image_Android Asynctask - Fatal编程技术网

Java 使用ImageView创建自定义视图,Asynctask不工作

Java 使用ImageView创建自定义视图,Asynctask不工作,java,android,image,android-asynctask,Java,Android,Image,Android Asynctask,我想以编程方式将视图添加到ViewFlipper: flipper.addView(anEpisode(name, null, description), i); 我的方法是: public View anEpisode(String n, String i, String d){ View v; LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT

我想以编程方式将视图添加到ViewFlipper:

flipper.addView(anEpisode(name, null, description), i); 
我的方法是:

public View anEpisode(String n, String i, String d){
    View v;
    LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v = inflater.inflate(R.layout.episodedescription, null);

    TextView nameOfEpisode = (TextView) v.findViewById(R.id.episodedescriptionname);
    ImageView imageOfEpisode = (ImageView) v.findViewById(R.id.episodedescriptionimage);
    TextView descriptionOfEpisode = (TextView) v.findViewById(R.id.episodedescriptiondescription);

    nameOfEpisode.setText(n);
    descriptionOfEpisode.setText(d);
    createUrlImage(imageOfEpisode, i);

    return v;
}
createUrlImage是:

private class CreateImage extends AsyncTask<String, Void, Drawable> {
    ImageView image;
    public CreateImage(ImageView img) {
        image = img;
    }
    protected void onPreExecute() {
    }

    protected Drawable doInBackground(String... urls) {
        InputStream is;
        Drawable d = null ;
        try {
            is = (InputStream)new URL(urls[0]).getContent();
            d = Drawable.createFromStream(is, "Image");
            return d;
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return d;
    }
    protected void onPostExecute(Drawable d) {
        image.setBackgroundDrawable(d);
    }
}
public void createUrlImage(ImageView img, String url){
    new CreateImage(img).execute(url);
}

问题是:它根本不显示图像,所以我不知道该怎么办。

我认为问题在于可绘制边界。在onPostExecute方法中设置边界


我认为问题在于可画边界。在onPostExecute方法中设置边界


你可以追踪你的代码,看看电脑是做什么的。我怎么做?我只知道如何使用debuger.ResourceType:资源不包含资源号为0x7f的包。。。。所有的页面都有这一行。你可以跟踪你的代码,看看电脑做什么。我怎么做?我只知道如何使用debuger.ResourceType:资源不包含资源号为0x7f的包。。。。所有页面都有一行。什么是getIntrinsicWidth和getIntrinsicHeight?好的,这是drawable的一个方法,但不起作用,现在它正在减慢应用程序的速度。是的,drawable的方法。错过了。尝试给出一个静态值来代替getIntrinsicWidth和getIntrinsicHeight。像d.setBounds 0,0,100,100;或者任何你认为不会超过实际高度和宽度的东西。好的,谢谢你,它与调试和我的手机一起工作,但与模拟器无关,没什么大不了的。它与getIntrinsicWidth和getIntrinsicHeight一起工作,只是我在评论中创建了UrlImageImageOfePiSode。我还不能给你奖金,但我会在我可以的时候给你。getIntrinsicWidth和getIntrinsicHeight是什么?好吧,这是drawable的一个方法,但不起作用,现在它正在减慢应用程序的速度。是的,方法从drawable开始。错过了。尝试给出一个静态值来代替getIntrinsicWidth和getIntrinsicHeight。像d.setBounds 0,0,100,100;或者任何你认为不会超过实际高度和宽度的东西。好的,谢谢你,它与调试和我的手机一起工作,但与模拟器无关,没什么大不了的。它与getIntrinsicWidth和getIntrinsicHeight一起工作,只是我在评论中创建了UrlImageImageOfePiSode。我还不能给你奖金,但我会在可能的时候给你。
 protected void onPostExecute(Drawable d) {
    d.setBounds (0, 0, getIntrinsicWidth(), getIntrinsicHeight());
    image.setBackgroundDrawable(d);
}