开发者

Load images from URL

I am trying to load some images in my app according to the following tu开发者_运维百科torial:

http://www.anddev.org/novice-tutorials-f8/imageview-with-loading-spinner-t49439.html

My problem is that I would like to have the same XML file for all my classes and just change the URL of the load image.

I'm using this code in my .java file:

final LoaderImageView image = new LoaderImageView(this, 
                                          "http://kostas-menu.gr/chania/santrivani.jpg");
image.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
                                       LayoutParams.WRAP_CONTENT));

And this in my xml:

<com.example.android.LoaderImageView
   android:layout_marginTop="10px"
   android:id="@+id/loaderImageView"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:gravity="center"
   image="http://developer.android.com/images/dialog_buttons.png"
   />

I would like to erase the line image="http://developer.android.com/images/dialog_buttons.png"but if I do it I'm not getting any image.

How could I call a separate image from my class?


You have already created xml with layout params, so you don't need do this again:

image.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
                                       LayoutParams.WRAP_CONTENT));

Try use this:

final LoaderImageView image = (LoaderImageView) findViewById(R.id.loaderImageView);
image.setImageDrawable("http://www.multimatograf.ru/assets/images/news-no-image.png");


I would simply use an ImageView on your Layout (which maybe has a dummy-picture) and then use Java to replace the Image: Link

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜