Display image from my own xml file - android

I am designing an android application where am storing my images in my local xml file like
imageview.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Source>
<ID>001</ID>
<Name>News</Name>
<image>
<title>News1</title>
<location>file:http:server_ip/Images/news1.png</location>
</image>
<image>
<title>News1</title>
<location>http:server_ip/Images/bnews2.png</location>
</image>
</Source>
Now i would like to display the image from this xml file into my imageview like-
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="here i would like to call my xml files image"/>
Edit:
I displayed this xml image with the help of loadimage. Now my only question is how to display the image from the xml file and display the image.

I am very wonder why your storing the image files such as news1.png and news2.png in your 'F' drive and how you except android to pack or bundle these inside the apk ,
you have two ways to do this
Solution 1:
please store it in your drawable or in assets folder, how android can pack/bundle this file with your apk.
Solution 2:
If you still want to keep your files in 'f' drive,just imitate like downloading the files from server and placing to drawable or assets
depending upon your need, i mean keep your 'f' drive as a localhost,
without downloading or importing to drawable you cannot use that image
inside your app.

Related

load file from asset whit subfolders

I have some problems while loading the file from the asset folder.
I wrote a code to load a txt file into a textview and everything works good.
If I try to put some order inside my txt file. I decided to put those files in subfolders in alphabetic order, because I have 800 text files. In this way my code is wrong. Is there a method to maintain the subfolders and load the file whitout specify where they are??
Thanks a lot

Image doesn't show up as my background in Android

I've added this attribute to my XML.
android:background="#drawable/background"
"#drawable/background" refers to the file background.psd which is located in the drawable folder.
The background does not appear when i run it (in the emulator).
What am i missing?
You can't use psd files as drawables. Try saving it as png.

invalid resource directory name: E:\workspace\.........\res red.png

I've been stuck on this ,
I have saved "red.png" in res folder,,but still getting error as
"invalid resource directory name: E:\workspace\.........\res red.png",
I tried
1.cleaning and rebuilding project
2.restart the eclipse
3.pasted "red.png" in sub folders of drawable ,
but not getting the solution.
please suggest me
I got the solution,,
created a folder named "drawable"
and pasted the image inside that folder,
thanks for your valuable response
There is easy way to use a image file in layout from res/drawable folder..
put this image in drawable folder and write in your xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/red"
android:orientation="vertical" >
</LinearLayout>
dont use file extention like .png
In android you can not set images directly to res folder , For putting images ***you have to create drawable folders*** like drawable-hdpi , drawable-xhdpi etc because in android we have many resolutions .
For more understanding please take a look at below link
http://developer.android.com/guide/practices/screens_support.html

load images from assets through XML

I use in my application more than 150 images, and 30 icons ! so I find it a little bit messy to put those images all together in Drawable folder, and as it is impossible to have sub-folders in drawable , I am trying to load my images from the Assets folder.
So to load images from assets programmatically its OK.
MY QUESTION is how to access Assets through XML?!
with drawable we use this :
<ImageView
android:id="#+id/img"
android:layout_width="25dp"
android:layout_height="25dp"
android:src=" **#drawable/ic_rate** "
/>
So what is the equivalent using assets.
Despite the fact that you should use drawables, you can define your own asset_drawable attribute as string than override the ImageViewto look for that atttibute and load the bitmap from assets. Your xml will be look like this
<com.foo.bar.AssetImageView
android:id="#+id/img"
android:layout_width="25dp"
android:layout_height="25dp"
app:asset_drawable="some/path/asset"
/>
You don't. An ImageView expects a drawable. Not all assets are drawables.
Drawables let you use images of different screen densities. Just use those. If you're struggling to stay organized, perhaps you could try using prefixes (e.g., prefix icons with ic). Another option would be to create a library project exclusively for icons, though it may be overkill.

Using JPEG as background on Android instead of PNG

I want to ask if Android accepts JPEG images instead of PNG, because PNG has bigger file size than JPEG.
I want to know how to use JPEG as background image in layout.xml file. Can you help me?
Just put a .jpg file in your res/drawable folder and refer to it as you normally would.
For example, if you put picture.jpg in your drawable folder, from one of your views you could just do the following.
<View
android:id="#+id/view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/picture" />

Categories

Resources