How can i display an image as my application background

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Postby surya.n.k » Mon Dec 24, 2007 6:25 am

Hi +-

this is showen when i open my application.


but i want the image fullscreen as slide show in gallary...


regards
surya
Attachments
test.PNG
test.PNG (75.13 KiB) Viewed 10630 times
surya.n.k
Developer
Developer
 
Posts: 26
Joined: Fri Dec 07, 2007 7:33 am

Top

Postby plusminus » Mon Dec 24, 2007 2:55 pm

Hey surya,

The "Hi" looks like a TextView...

So, please post your "main.xml" of your are usind an xml-layout or your onCreate()-Code otherwise.

Merry Christmas,
plusminus :xmas:
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby surya.n.k » Tue Dec 25, 2007 7:05 am

this is my main.xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:orientation="vertical"
  6.  
  7.    android:layout_width="fill_parent"
  8.  
  9.    android:layout_height="fill_parent"
  10.  
  11.    >
  12.  
  13. <TextView  
  14.  
  15.    android:layout_width="fill_parent"
  16.  
  17.    android:layout_height="wrap_content"
  18.  
  19.    android:text="Hi"
  20.  
  21.    />
  22.  
  23.    
  24.  
  25.     <Gallery id="@+id/gallery"
  26.  
  27.        android:layout_width="fill_parent"
  28.  
  29.        android:layout_height="wrap_content"
  30.  
  31.        android:gravity="center"
  32.  
  33. />
  34.  
  35.    
  36.  
  37. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4





here is my onCreate method any changes to be done............

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class ImageDisplay extends Activity {
  2.  
  3.     /** Called when the activity is first created. */
  4.  
  5.     @Override
  6.  
  7.     public void onCreate(Bundle icicle) {
  8.  
  9.         super.onCreate(icicle);
  10.  
  11.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  12.  
  13.        
  14.  
  15.         setContentView(R.layout.main);
  16.  
  17.  
  18.  
  19.         ((Gallery) findViewById(R.id.gallery)).setAdapter(new DrawImages(this));
  20.  
  21.     }
  22.  
  23. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



and DrawImages is the tutorial which is given by you.......
surya.n.k
Developer
Developer
 
Posts: 26
Joined: Fri Dec 07, 2007 7:33 am

Postby plusminus » Wed Dec 26, 2007 11:40 pm

Hello surya,

simply remove this from your main.xml:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <TextView  
  2.    android:layout_width="fill_parent"
  3.    android:layout_height="wrap_content"
  4.    android:text="Hi"
  5.    />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


The topmost bar(with clock) is not overlayable as far as i know.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby surya.n.k » Thu Dec 27, 2007 6:40 am

Hi +-


thanks i got the solution...


can i have any tutorial for writting texts on to the images with different styles of font and how to load ttf files in to applicaiton.

thanks & regards
surya
surya.n.k
Developer
Developer
 
Posts: 26
Joined: Fri Dec 07, 2007 7:33 am

Postby plusminus » Fri Dec 28, 2007 1:21 pm

Hello surya,

the :src: PizzaTimer-Tutorial (click) draws text with different sizes onto a Canvas.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby snowtiger » Mon Jan 07, 2008 3:00 pm

I have a similiar question.

I want to access the drawables in a dynamic way, the static call of R.drawable.some_drawable works of course, but i have about 50 states and 7 icons for every state. So i just want to access the corresponding icon file, i.e. icon0_1.png for state 0 and button 1 with:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Drawable icon = Drawable.createFromPath("MyApp/res/drawable/icon"+currentStatus+"_"+buttonId+".png");
  2.  
  3. MyImageButton.setImageDrawable(icon);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

Unfortunately it doesn't work, if i just use
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. MyImageButton.setImageResource(R.drawable.icon0_1);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
it works as mentioned above. How can i get the dynamic version working?

Thx in advance
snowtiger
Developer
Developer
 
Posts: 34
Joined: Fri Dec 21, 2007 10:44 am

Postby plusminus » Mon Jan 07, 2008 4:56 pm

Hello snowtiger,

it doesn't work as you cannot access the images in the way you are trying.

The images you've put under "/res/drawable/xyz.png" get compiled into your *.apk (Activity-File) :!:

:idea: Solution: You can determine the Resource IDs this way (using getResources().getIdentifier(String, String, String); ):
I have a file bug.png in the "/res/drawable/":
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. int resID = getResources().getIdentifier("org.anddev.android.testproject:drawable/bug", null, null);
  2. // or
  3. int resID = getResources().getIdentifier("bug", "drawable", "org.anddev.android.testproject");
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Let us know if it helped you :)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby snowtiger » Mon Jan 07, 2008 5:26 pm

wooohaaaaa, how cool, it works of course:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String icon = "icon" + currentStatus + "_" + buttonId;
  2.                 int resID = getResources().getIdentifier(icon, "drawable", "de.uniba.android");
  3.                 myImageButton.setImageResource(resID);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

I found out, that Drawable icon = Drawable.createFromPath("data/misc/icon" + currentStatus + "_" + buttonId + ".png"); works only, if the file is pushed somewhere on the emulator, like in app/misc/...

But thanks so much, this site is a thousand times better than google's documentation :)
snowtiger
Developer
Developer
 
Posts: 34
Joined: Fri Dec 21, 2007 10:44 am

Postby Emistro45 » Sun Apr 12, 2009 10:13 pm

i dont understand....i use the code(main.xml) to loaad my background..wont work tho..y?:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. android:background="@drawable/untitled.bmp"
  3.  
  4.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

it wont compile nor run and when i look in the layout window the background is there....the image is in the drawable folder in the application...do i still need to merge it with the emulator er wut?
Emistro45
Freshman
Freshman
 
Posts: 2
Joined: Sun Apr 12, 2009 9:32 pm

Postby qwerty9586 » Wed Aug 05, 2009 10:44 pm

Emistro45 wrote:i dont understand....i use the code(main.xml) to loaad my background..wont work tho..y?:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. android:background="@drawable/untitled.bmp"
  2.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4

it wont compile nor run and when i look in the layout window the background is there....the image is in the drawable folder in the application...do i still need to merge it with the emulator er wut?


I know this is late (hope I'm not necroposting). You have to remove the extension. That's what happened to me when i tried to add a background.
qwerty9586
Freshman
Freshman
 
Posts: 2
Joined: Wed Aug 05, 2009 10:41 pm

Postby qwerty9586 » Wed Aug 05, 2009 10:53 pm

On another note, I'd like to add how to make a transparent/translucent background.

Add the transparency to the background image in a graphics editor and save as a PNG. Then in your manifest, add the android:theme line like so:

<activity android:name="yourActivityName"
android:theme="@android:style/Theme.Translucent" />

And then in the activity's XML, add the android:background like on the first page of this thread.
qwerty9586
Freshman
Freshman
 
Posts: 2
Joined: Wed Aug 05, 2009 10:41 pm

Re: How can i display an image as my application background

Postby irsyad » Thu Jun 10, 2010 7:27 am

Hi

Can you help with with this error? I'm new to Eclipse and currently doing Major Project for school.

"Unparsed aapt error(s)! Check the console for output."
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
</LinearLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:padding="5dip"
   android:background="@drawable/ferry">
   </RelativeLayout>


I tried to apply a background image for my application but I can't get through the error mentioned above. I've been having that same error.

Thank you
Dayne
irsyad
Freshman
Freshman
 
Posts: 2
Joined: Thu Jun 10, 2010 7:21 am

Re: How can i display an image as my application background

Postby nozo » Sun Jun 13, 2010 8:47 am

Also I need to set background of app. But how to know what dimensions to be picture? Maby my app will be running on phone with resolution 240x320, maby on 320x480.
nozo
Freshman
Freshman
 
Posts: 3
Joined: Sat May 22, 2010 1:56 am

Re: How can i display an image as my application background

Postby danjoeMar » Tue Jun 15, 2010 3:40 am

plusminus or anyone,

You seem to be very knowledgeable. I have a simple question for you or whoever can answer it. I think it relates indirectly to this post at least to how it applies to my exact problem. Anyhow, my question is this:

In regards to main.xml, if you post a layout in that file it now is static, correct? In other words you cannot add stuff to it dynamically through Java Code, correct?

I ask this question because I would like a static layout and background, however I need to add images to this layout dynamically so maybe I need to rethink what this all means.

Thanks for your time and help in advance.

Dan
danjoeMar
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Jun 15, 2010 3:21 am

Top
PreviousNext

Return to General

Who is online

Users browsing this forum: No registered users and 5 guests