Gallery item - size & background

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

Gallery item - size & background

Postby Johan » Mon Mar 30, 2009 8:41 am

Hi,

I've made a Gallery and I used a selector to show a slightly different background when an item is selected or clicked:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  5.  
  6.         <item   android:state_pressed="false"
  7.  
  8.                         android:state_selected="true"
  9.  
  10.                         android:drawable="@drawable/selected"
  11.  
  12.         />                             
  13.  
  14.         <item   android:state_pressed="true"
  15.  
  16.                         android:drawable="@drawable/pressed"
  17.  
  18.         />
  19.  
  20.         <item   android:drawable="@drawable/default_item"
  21.  
  22.         />
  23.  
  24. </selector>
  25.  
  26.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

So far so good, I can see the different backgrounds when I select or click on an item in the gallery.
Now I wanted to increase the size of an item when it is selected. I used the 'setOnItemSelectedListener' of the Gallery object:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. mGallery.setOnItemSelectedListener(new OnItemSelectedListener() {
  3.  
  4.  
  5.  
  6.         public void onItemSelected(AdapterView<?> parent, View v,int position, long id) {
  7.  
  8.                 v.setLayoutParams(new Gallery.LayoutParams(150, 150));
  9.  
  10.                 ...
  11.  
  12.         }
  13.  
  14. }
  15.  
  16.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Now the size of an selected item in the gallery is bigger than the size of the others. But the background of this item isn't changed anymore. Can anyone tell me why this doesn't work and how I can make it work?

thanks
Johan
Freshman
Freshman
 
Posts: 7
Joined: Fri Feb 20, 2009 3:30 pm

Top

Postby Johan » Tue Apr 21, 2009 12:28 pm

no one?
Johan
Freshman
Freshman
 
Posts: 7
Joined: Fri Feb 20, 2009 3:30 pm

Postby padde » Tue Apr 21, 2009 1:31 pm

If the background is a fix drawable then simply include a second one with
the right resolution and set the backgrounds accordingly.
If the background is a shape then try to reset the background after you
changed the size.. maybe the background is onetime calculated and fittet
when you set it and cant change dynamic.

Greets
Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 6 guests