A android.widget.Gallery - Example

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

Postby pskink » Thu Mar 18, 2010 11:46 am

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

have fun


btw if your're paranoic about GC the existing cusm Animations can be easly reused that way minimizing GC activity
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Postby Tactition » Mon May 10, 2010 6:42 pm

This is a great tutorial thanks a lot for posting it. I was wondering though, if there is any way to make the gallery wrap? Like, right now the gallery scrolls to the edge and stops, but I would like to have my gallery scroll from the last item to the first item again in a cycle.

Is this possible and if so how is it done?
Tactition
Once Poster
Once Poster
 
Posts: 1
Joined: Mon May 10, 2010 6:38 pm

Re: A android.widget.Gallery - Example

Postby SamAndroid » Thu May 20, 2010 7:54 am

Hey Plusminus .... i ve been reading your tutorials ... You really make things easy to understand ...

What if i want to do something when user taps on a photo? how to handle click events?
Sam
SamAndroid
Junior Developer
Junior Developer
 
Posts: 11
Joined: Fri Apr 02, 2010 7:48 am
Location: Pakistan

Re: A android.widget.Gallery - Example

Postby glouzaille » Thu May 27, 2010 11:14 pm

hello, and great work again.
I'm interested too in the gallery scrolling where from the end of the gallery, it starts again, some sort of never ending gallery. anyone has a clue?
glouzaille
Freshman
Freshman
 
Posts: 5
Joined: Mon Nov 23, 2009 2:32 pm

Re: A android.widget.Gallery - Example

Postby tallal_t » Thu Jul 15, 2010 6:56 am

Hi I want to add a video in place of Images in the Image view under the gallery, for now i have just made a video view and replaces it with the image view where the images are displayed . but see no video
i want to have a video gallery sort of thing .

with thumbnails of videos in the gallery and and video view in the bottom .

any help ?
tallal_t
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jul 14, 2010 3:11 pm

Re: A android.widget.Gallery - Example

Postby h4ch3 » Mon Aug 09, 2010 12:01 pm

glouzaille wrote:hello, and great work again.
I'm interested too in the gallery scrolling where from the end of the gallery, it starts again, some sort of never ending gallery. anyone has a clue?



I also want to know this, anyone?
h4ch3
Freshman
Freshman
 
Posts: 3
Joined: Mon Jul 12, 2010 4:43 pm

Top

Re: A android.widget.Gallery - Example

Postby megadeath2005 » Wed Sep 22, 2010 7:42 pm

I have a problem with the galleries on the first item appears in the center
How to align the first element to the left??

thanks
megadeath2005
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jan 06, 2010 2:53 pm
Location: Colombia

Re: A android.widget.Gallery - Example

Postby ponkin » Tue Sep 28, 2010 10:22 pm

h4ch3 wrote:
glouzaille wrote:hello, and great work again.
I'm interested too in the gallery scrolling where from the end of the gallery, it starts again, some sort of never ending gallery. anyone has a clue?



I also want to know this, anyone?


Hello? I have implemented that kind of functionality with following:
1) Create your own adapter for Gallery,
Code: Select all
class GalleryAdapter extends BaseAdapter

2) implement method in your GalleryAdapter
Code: Select all
public int getCount() {
     return Integer.MAX_VALUE;
   }

3)In all methods replace position variable with your private method call
Code: Select all
   int getRealPosition(int position){
     position = position % mGalleryItems.length;
     if (position < 0)
         position = position + mGalleryItems.length;
     return position;
   }

where mGalleryItems - array of your Gallery items
4) And don`t forget to show "middle" of your infinite gallery
Code: Select all
mGallery.setSelection(Integer.MAX_VALUE / 2, true);


This is it. However it`s a tricky but works for me.
ponkin
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Sep 28, 2010 10:10 pm
Location: Russia

Re: A android.widget.Gallery - Example

Postby Boni2k » Tue Dec 07, 2010 3:36 am

megadeath2005 wrote:I have a problem with the galleries on the first item appears in the center
How to align the first element to the left??

thanks

I'm very interested in that, too. I tried to extend the Gallery class and implement my own methods but the interesting ones are marked private. I don't like having these extra spaces to the left and right of the gallery...
Boni2k
Experienced Developer
Experienced Developer
 
Posts: 88
Joined: Sun Dec 20, 2009 9:46 pm

Re: A android.widget.Gallery - Example

Postby Efefes » Thu Dec 09, 2010 4:14 pm

Hello. I'm new to android and somewhat new to programming as well, so I have a few questions after trying out this tutorial.

1. I got the basic version of the tutorial working, but however the images are slightly overlapping. How do I cease that from happening? I want the next picture to start 1 pixel away from the previous one.

2. I want to add onClick functionality, but using the previous sample made me unable to use the scrolling anymore.

3. I want to add text below the gallery which changes depending on which picture is chosen.

I'm newbieish to this stuff and couldn't figure it out on my own with the tutorials, so any help is greatly appreciated. Thanks in advance and thanks for the tutorial
Efefes
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 09, 2010 2:18 pm

Re: A android.widget.Gallery - Example

Postby Boni2k » Thu Dec 09, 2010 4:27 pm

Efefes wrote:Hello. I'm new to android and somewhat new to programming as well, so I have a few questions after trying out this tutorial.

1. I got the basic version of the tutorial working, but however the images are slightly overlapping. How do I cease that from happening? I want the next picture to start 1 pixel away from the previous one.

2. I want to add onClick functionality, but using the previous sample made me unable to use the scrolling anymore.

3. I want to add text below the gallery which changes depending on which picture is chosen.

I'm newbieish to this stuff and couldn't figure it out on my own with the tutorials, so any help is greatly appreciated. Thanks in advance and thanks for the tutorial


1. use .setSpacing(pixel) for your gallery
2. Take a look here: http://developer.android.com/guide/tuto ... llery.html
3. it can be combined your 2. point
Boni2k
Experienced Developer
Experienced Developer
 
Posts: 88
Joined: Sun Dec 20, 2009 9:46 pm

Re: A android.widget.Gallery - Example

Postby Efefes » Thu Dec 09, 2010 5:55 pm

Boni2k wrote:
Efefes wrote:Hello. I'm new to android and somewhat new to programming as well, so I have a few questions after trying out this tutorial.

1. I got the basic version of the tutorial working, but however the images are slightly overlapping. How do I cease that from happening? I want the next picture to start 1 pixel away from the previous one.

2. I want to add onClick functionality, but using the previous sample made me unable to use the scrolling anymore.

3. I want to add text below the gallery which changes depending on which picture is chosen.

I'm newbieish to this stuff and couldn't figure it out on my own with the tutorials, so any help is greatly appreciated. Thanks in advance and thanks for the tutorial


1. use .setSpacing(pixel) for your gallery
2. Take a look here: http://developer.android.com/guide/tuto ... llery.html
3. it can be combined your 2. point


Thank you.

1. I got this to work with the hello-gallery tutorial in developer.android.com but not sure how to use it with this tutorial. Could you explain the specific piece of code? I'm honestly just starting out with programming, and having difficulties with the most basic things.

2. I went through this, but there's one thing puzzling me.

public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = a.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground, 0);
a.recycle();
}
What does this do? whats 'styleable' ? this piece of code is giving me errors for missing that, how should I go on about adding it and what should I add there? a background?

3. I got the onclick thing working with Toast, but I still can't figure out how to put normal text below there, and how to get the trigger from the "current image". I'd like to add a few lines of text for each picture, and Toast is not exactly the tool I want to use with that. I went through the TextView methods, but still can't quite figure out how to use it as I wish, how to place my text in certain coords or below an object.

Sorry for having such limited comprehension and thanks for help, it's greatly appreciated.
Efefes
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 09, 2010 2:18 pm

Re: A android.widget.Gallery - Example

Postby Boni2k » Thu Dec 09, 2010 6:13 pm

Efefes wrote:Thank you.

1. I got this to work with the hello-gallery tutorial in developer.android.com but not sure how to use it with this tutorial. Could you explain the specific piece of code? I'm honestly just starting out with programming, and having difficulties with the most basic things.

2. I went through this, but there's one thing puzzling me.

public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = a.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground, 0);
a.recycle();
}
What does this do? whats 'styleable' ? this piece of code is giving me errors for missing that, how should I go on about adding it and what should I add there? a background?

3. I got the onclick thing working with Toast, but I still can't figure out how to put normal text below there, and how to get the trigger from the "current image". I'd like to add a few lines of text for each picture, and Toast is not exactly the tool I want to use with that. I went through the TextView methods, but still can't quite figure out how to use it as I wish, how to place my text in certain coords or below an object.

Sorry for having such limited comprehension and thanks for help, it's greatly appreciated.


1. As my time is quite spare right now I'm afraid I can't tell you much about it now. Or you could tell me what exactly you'd like to know.

2. you can remove everything you quoted. It's just for the background, which you don't actually require. Styleable is something you define in a file called attrs.xml in your /res/values/ folder. I think it's written in the tutorial, too.

3. Well I assume you added a textview in your XML layout? Something like this:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/RelativeLayout01"
   android:layout_height="fill_parent" android:layout_width="fill_parent" android:background="#FFFBF7">
<Gallery
    android:id="@+id/gallery"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
/>
<TextView android:text="TEXT" android:layout_width="fill_parent" android:id="@+id/text"  android:layout_height="45dip" android:layout_below="@+id/gallery></TextView>
</RelativeLayout>


If you have, replace the Toast part of your code with TextView text = (TextView)findViewById(R.id.text); text.setText("Blablabla")

What do you plan to do in your application? I found out that using the gallery widget is far too unflexible.
Boni2k
Experienced Developer
Experienced Developer
 
Posts: 88
Joined: Sun Dec 20, 2009 9:46 pm

Re: A android.widget.Gallery - Example

Postby Efefes » Thu Dec 09, 2010 7:38 pm

Long story short I'm just making a cool-looking memo for a certain game I'm often playing in a location where I can't access the internet. Gallery being pictures of the characters and below being the actual notes for each character.

Also trying to understand android programming while at it.

Anyway thanks, I think that cleared up 2. and 3 for now - I'll try them tomorrow. As for 1, with the tutorial copied from the other site I could straight up just add the .setSpacing(0); to the code because the gallery entity(is this term correct?) was there like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Gallery g = (Gallery) findViewById(R.id.gallery);
  2.             g.setAdapter(new ImageAdapter(this));
  3.             g.setSpacing(0);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


the other gallery-example is built in a bit different way, confusing me how do I actually call the gallery's methods.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class GalleryExample extends Activity {
  2.         @Override
  3.         public void onCreate(Bundle icicle) {
  4.                 super.onCreate(icicle);
  5.                 setContentView(R.layout.main);
  6.                 ((Gallery) findViewById(R.id.gallery))
  7.                                 .setAdapter(new ImageAdapter(this));
  8.                
  9.         }
  10.  
  11. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


and in the public class ImageAdapter extends BaseAdapter I have
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public View getView(int position, View convertView, ViewGroup parent) {
  2.                 ImageView i = new ImageView(this.myContext);
  3.                
  4.                 i.setImageResource(this.myImageIds[position]);
  5.                 i.setScaleType(ImageView.ScaleType.FIT_XY);
  6.                 i.setLayoutParams(new Gallery.LayoutParams(200, 200));
  7.                
  8.         i.setOnClickListener(new OnClickListener(){ //etc
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


It must be something very simple i'm not getting here.
Efefes
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 09, 2010 2:18 pm

Re: A android.widget.Gallery - Example

Postby Boni2k » Thu Dec 09, 2010 7:47 pm

To your second code:
((Gallery) findViewById(R.id.gallery)).setAdapter(new ImageAdapter(this));

is basically the same as if you'd do:
Gallery gallery = ((Gallery) findViewById(R.id.gallery));
gallery.setAdapter(new ImageAdapter(this));
just in a shorter version.

The getView Method in your third code is defining the layout of each gallery item. Each item is an ImageView and the code says it should get its image from mImageIds and should have 200x200 dimension.
Boni2k
Experienced Developer
Experienced Developer
 
Posts: 88
Joined: Sun Dec 20, 2009 9:46 pm

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests