A android.widget.Gallery - Example

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Re: images from sd card

Postby Krizzle85 » Fri Mar 27, 2009 10:10 am

saty_32016 wrote:Hi ,
how can we take image from sdcard and put that into in a array?

kartikdo wrote:what if I want to load images from SD card or from phone using the above example.


Hi,

Sorry for asking the same question but i coudn't find an anwser on how to fill you gallery with pictures or photo's from the SD card.

any help would be nice :)
Krizzle85
Freshman
Freshman
 
Posts: 2
Joined: Thu Mar 26, 2009 11:11 am

Top

Quick Question

Postby rsmitty1025 » Fri Jul 17, 2009 3:12 pm

Hey All,

First off, great tutorial.

Quick Question. I want to have a TextField that updates with the name of the Image being shown at the time. Any Ideas on how to do this?

Thanks everyone!
rsmitty1025
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Jul 17, 2009 3:06 pm

getScale & getAlpha

Postby spuzvica » Sun Aug 09, 2009 9:34 pm

Zachary wrote:there is a problem, the getScale() and getAlpha are removed from 0.9 SDK, I can't show the image bigger or smaller when scrolling, the people who use the tutorial code should have this problem.
How can I do to walk around it, anybody has some suggestion?
Thanks a lot


Anyone managed to resolve this one in cupcake?
spuzvica
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Aug 09, 2009 9:27 pm

Re: getScale & getAlpha

Postby khann » Tue Sep 01, 2009 9:00 pm

spuzvica wrote:
Zachary wrote:there is a problem, the getScale() and getAlpha are removed from 0.9 SDK, I can't show the image bigger or smaller when scrolling, the people who use the tutorial code should have this problem.
How can I do to walk around it, anybody has some suggestion?
Thanks a lot


Anyone managed to resolve this one in cupcake?


+1 anyone?!
khann
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Aug 04, 2009 8:20 pm

Postby xcallmejudasx » Tue Oct 06, 2009 8:28 pm

Excellent post, has been a great help.

Simple question; how do I get the gallery located on the bottom of the view? I've tried android:gallery="bottom" but that doesn't do anything.
xcallmejudasx
Freshman
Freshman
 
Posts: 3
Joined: Tue Oct 06, 2009 8:25 pm
Location: Houston, TX

Postby Legend » Tue Oct 13, 2009 3:20 pm

Thanks a lot for the tutorial. I tried this but for some reason, my image does not get enlarged when clicked... Is there any specific reason why this might happen? Also, I was wondering if its possible to get like a small glow around the image when clicked... Any suggestions please?
Legend
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Sep 29, 2009 1:04 am

Top

Postby lj.asap » Wed Nov 18, 2009 2:01 pm

Hello to all,
thanks for this code, it works like application,
but if i want to include gallery in a widget for home?
i try to do it but it doesn't work..
Can you help me?
lj.asap
Freshman
Freshman
 
Posts: 2
Joined: Wed Nov 18, 2009 1:56 pm

Postby android78 » Mon Feb 15, 2010 4:31 am

This is great, and I'm able to use the Gallery, however I would like to extend the gallery and it doesn't seem to work at all. What I'm doing is changing the following from where I use it in XML (I'm not referencing the gallery anywhere else in code yet):
<Gallery android:id="testgal">
to
<org.anmay.myprogramm.MyGallery android:id="testgal">

and, in the class I am extending the gallery as follows:

public class MyGallery extends Gallery{
public MyGallery(Context context){
super(context)
}
}

Now, if I use the unextended Gallery, there is no issues, it just displays nothing.
If I use my extended gallery, the application crashes.

Any ideas?
android78
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Feb 15, 2010 4:14 am

Postby jpprade » Sun Feb 21, 2010 11:42 pm

Thanks for this tutorial it saved me a lot of time !

But Is it possible to display image vertically and not horizontally ?

thanks !
jpprade
Freshman
Freshman
 
Posts: 3
Joined: Sun Feb 21, 2010 11:38 pm

Postby ma888 » Thu Mar 11, 2010 4:00 am

Thanks keiko11245 - I got the scaled images working thanks to your post.

I added ItemSelectedListener on the Gallery instance to update the view upon selection change.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
  2.  
  3.         public void onItemSelected(AdapterView<?> parentView, View childView, int position, long id) {
  4.  
  5.                 imageAdapter.notifyDataSetChanged();
  6.  
  7.         }
  8.  
  9.         public void onNothingSelected(AdapterView<?> arg0) {
  10.  
  11.                 // Do nothing
  12.  
  13.         }
  14.  
  15. });
  16.  
  17.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
ma888
Freshman
Freshman
 
Posts: 2
Joined: Thu Mar 11, 2010 3:54 am

Re: getScale & getAlpha

Postby Profete162 » Sat Mar 13, 2010 6:46 pm

khann wrote:
spuzvica wrote:
Zachary wrote:there is a problem, the getScale() and getAlpha are removed from 0.9 SDK, I can't show the image bigger or smaller when scrolling, the people who use the tutorial code should have this problem.
How can I do to walk around it, anybody has some suggestion?
Thanks a lot


Anyone managed to resolve this one in cupcake?


+1 anyone?!



+2 anyone???


yesnto wrote:Does anyone know how to loop their gallery?


Woule be really interested too.



Thank a lot for any answer on one of these 2 questions!
Profete162
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Nov 27, 2009 6:07 pm

Re: getScale & getAlpha

Postby ma888 » Sat Mar 13, 2010 8:33 pm

About the scaling -- I did it manually through LayoutParams, based on the offset:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public View getView(int position, View convertView, ViewGroup parent) {
  2.  
  3.  
  4.  
  5.                 ImageView view = null;
  6.  
  7.  
  8.  
  9.                 if (convertView == null) {
  10.  
  11.                         view = new ImageView(this.context);
  12.  
  13.                 } else {
  14.  
  15.                         view = (ImageView) convertView;
  16.  
  17.                 }
  18.  
  19.  
  20.  
  21.                 Drawable image = this.images.get(position);
  22.  
  23.                 int selected = ((Gallery) parent).getSelectedItemPosition();
  24.  
  25.  
  26.  
  27.                 view.setImageDrawable(image);
  28.  
  29.                 view.setScaleType(ImageView.ScaleType.CENTER);
  30.  
  31.  
  32.  
  33.                 float scale = getScale(position - selected);
  34.  
  35.                 int width = Math.round(IMAGE_WIDTH * scale);
  36.  
  37.                 int height = Math.round(IMAGE_HEIGHT * scale);
  38.  
  39.                 view.setLayoutParams(new Gallery.LayoutParams(width, height));
  40.  
  41.  
  42.  
  43.                 return view;
  44.  
  45.         }
  46.  
  47.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


getScale() is the same method mentioned before.
ma888
Freshman
Freshman
 
Posts: 2
Joined: Thu Mar 11, 2010 3:54 am

Re: getScale & getAlpha

Postby pskink » Sat Mar 13, 2010 10:25 pm

khann wrote:
spuzvica wrote:
Zachary wrote:there is a problem, the getScale() and getAlpha are removed from 0.9 SDK, I can't show the image bigger or smaller when scrolling, the people who use the tutorial code should have this problem.
How can I do to walk around it, anybody has some suggestion?
Thanks a lot


Anyone managed to resolve this one in cupcake?


+1 anyone?!


here you have two solutions: one easy but not impressive - top gallery and second a bit complex but more fancy - bottom gallery
Attachments
Gallery.tar.gz
(83.1 KiB) Downloaded 466 times
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby pskink » Mon Mar 15, 2010 7:58 am

again, two solutions: one easy but not impressive with selected image always scaled- top gallery and second with smooth scaling animation - bottom gallery
Attachments
Gallery.tar.gz
(81.63 KiB) Downloaded 394 times
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby pskink » Mon Mar 15, 2010 1:35 pm

final version: added custom animation attributes (used in xml layouts) and horizontal offset attribute. also simplified zoom out animation

have fun
Attachments
Gallery.tar.gz
(82.63 KiB) Downloaded 971 times
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 7 guests