background color & background image

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

background color & background image

Postby kumar4u » Sat Jan 09, 2010 7:05 am

Hi every body,

I have an application, in that i have set an image as background, now i have to change my back ground color and on that i have to set an image in the center of the screen. Iam able to do any one of the activity at a time means i am able to change the background color of my application at that time iam not able to set my image and viceversa(able to set background image and unable to set background color) just i need a solution to set both (backgound color and background image) at a time.

If any one have the solution please share with me.

Thanks
sabs
kumar4u
Freshman
Freshman
 
Posts: 7
Joined: Fri Dec 04, 2009 2:51 pm

Top

Postby jwei512 » Sat Jan 09, 2010 10:12 am

Could you clarify what exactly you need to do? Is it that you want to set the image background to a color, and also add an image in the center of that background color?
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby spring » Sat Jan 09, 2010 11:57 am

I think,it probable that he want to set the background color at first and then set the image at the center of the screen.
spring
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Jan 09, 2010 4:37 am
Location: China

Postby kumar4u » Sat Jan 09, 2010 3:15 pm

spring wrote:I think,it probable that he want to set the background color at first and then set the image at the center of the screen.


Hi spring,

what you have understood is exactly correct first i have to set the background color and then set the image at the center of the screen. i am not sure it is possible or not. if u have any solution please share with me...

Thanks
sabs
kumar4u
Freshman
Freshman
 
Posts: 7
Joined: Fri Dec 04, 2009 2:51 pm

Postby jwei512 » Sat Jan 09, 2010 4:27 pm

You could have two linear layouts? The first one that takes up the entire screen with a large padding (like 50dip) and then have another linear layout inside of that one with gravity = center.

Then you can set the first linear layout to have some background color, and set the 2nd linear layout to have the image and it will appear as if it were "inside" of the first layout.

Does this make sense?
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby pskink » Sat Jan 09, 2010 5:23 pm

jwei512 wrote:You could have two linear layouts?
Does this make sense?


well, it will work but it's wasting resources.

better use compound Drawable like LevelListDrawable or LayerDrawable

pskink
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Postby sabs » Mon Jan 11, 2010 8:27 am

pskink wrote:
jwei512 wrote:You could have two linear layouts?
Does this make sense?


well, it will work but it's wasting resources.

better use compound Drawable like LevelListDrawable or LayerDrawable

pskink


Hi thanks for giving reply.
I have got the little idea, i have tried both of your suggestions, but iam unable to get clear idea. Can any one clearly explain any of the solution which is provided above so that i can get rid of my problem.

thanks
sabs
sabs
Developer
Developer
 
Posts: 32
Joined: Fri Dec 04, 2009 2:55 pm

Postby spring » Mon Jan 11, 2010 10:57 am

I do not know if this code is you wanted.I hope it will valuable for you.

layout:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3.  
  4.  
  5. <RelativeLayout
  6.  
  7. xmlns:android="http://schemas.android.com/apk/res/android"
  8.  
  9.         android:layout_width="fill_parent"
  10.  
  11.         android:layout_height="fill_parent"
  12.  
  13.         android:background="#ff0000"
  14.  
  15.          >
  16.  
  17.         <ImageView
  18.  
  19.                 android:id="@+id/test"
  20.  
  21.                 android:src="@drawable/icon"
  22.  
  23.                 android:layout_width="wrap_content"
  24.  
  25.                 android:layout_height="wrap_content"
  26.  
  27.                 android:layout_centerInParent="true"
  28.  
  29.         />
  30.  
  31. </RelativeLayout>
  32.  
  33.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
Attachments
p1.png
screen shot
p1.png (10.01 KiB) Viewed 4886 times
spring
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Jan 09, 2010 4:37 am
Location: China

Postby sabs » Mon Jan 11, 2010 11:54 am

spring wrote:I do not know if this code is you wanted.I hope it will valuable for you.

layout:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <RelativeLayout
  4. xmlns:android="http://schemas.android.com/apk/res/android"
  5.         android:layout_width="fill_parent"
  6.         android:layout_height="fill_parent"
  7.         android:background="#ff0000"
  8.          >
  9.         <ImageView
  10.                 android:id="@+id/test"
  11.                 android:src="@drawable/icon"
  12.                 android:layout_width="wrap_content"
  13.                 android:layout_height="wrap_content"
  14.                 android:layout_centerInParent="true"
  15.         />
  16. </RelativeLayout>
  17.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Thanks a lot for giving the solution it worked fine
sabs
Developer
Developer
 
Posts: 32
Joined: Fri Dec 04, 2009 2:55 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests