Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7794921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:55:04+00:00 2026-06-01T22:55:04+00:00

I have a gallery viewer for an Android application. I need to show, first,

  • 0

I have a gallery viewer for an Android application.

I need to show, first, a big picture, and then below it, the thumbnails of other pictures.
After 5 seconds, the thumbnails disappear, and when the user touches the screen, the thumbnails should appears again.

The problem here is that, if the thumbnails appear again, they won’t disappear anymore, thus this only works the first time.

How could I fix this issue?

This is my layout code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/GalleryImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" >
    </ImageView>

    <Gallery
        android:id="@+id/GalleryThumbnails"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/GalleryImage" />
</RelativeLayout>

This is my implementation:

public class GalleryView extends Activity {
    Integer[] pics = { R.drawable.antartica1, R.drawable.antartica2, R.drawable.antartica3, R.drawable.antartica4, R.drawable.antartica5, R.drawable.antartica6, R.drawable.antartica7,
            R.drawable.antartica8, R.drawable.antartica9, R.drawable.antartica10 };
    ImageView imageView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gallery_view_layout);

        final Gallery ga = (Gallery) findViewById(R.id.GalleryThumbnails);
        ga.setAdapter(new ImageAdapter(this));

        imageView = (ImageView) findViewById(R.id.GalleryImage);

        // We show the first image when creating the view gallery

        imageView.setScaleType(ImageView.ScaleType.CENTER);
        imageView.setImageResource(pics[0]);

        // Hiding the thumbnails after 5 seconds

        final View v = new View(this);
        v.postDelayed(new Runnable() {
            public void run() {
                ga.setVisibility(View.GONE);
            }
        }, (long) 5000);

        // Showing the thumbnails again when touching the screen
        // TODO: Not working yet

        imageView.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    ga.setVisibility(View.VISIBLE);
                }
                return false;
            }
        });

        ga.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                imageView.setScaleType(ImageView.ScaleType.CENTER);
                imageView.setImageResource(pics[arg2]);
            }
        });
    }

    public class ImageAdapter extends BaseAdapter {

        private Context ctx;
        int imageBackground;

        public ImageAdapter(Context c) {
            ctx = c;
            TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
            imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
            ta.recycle();
        }

        public int getCount() {

            return pics.length;
        }

        public Object getItem(int arg0) {
            return arg0;
        }

        public long getItemId(int arg0) {
            return arg0;
        }

        // Thumbnails gallery

        public View getView(int arg0, View arg1, ViewGroup arg2) {
            ImageView iv = new ImageView(ctx);
            iv.setImageResource(pics[arg0]);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setLayoutParams(new Gallery.LayoutParams(200, 120));
            iv.setBackgroundResource(imageBackground);
            return iv;
        }
    }
}

Thanks a lot in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:55:06+00:00Added an answer on June 1, 2026 at 10:55 pm

    This is strange code

       final View v = new View(this);
        v.postDelayed(new Runnable() {
            public void run() {
                ga.setVisibility(View.GONE);
            }
        }, (long) 5000);
    

    You are creating a dangling view in order to schedule a delayed call to ga.

    I guess you meant

    private Gallery ga; // make ga to a member
    
    private void scheduleHide ()
    {
        ga.postDelayed(new Runnable() {
            public void run() {
                ga.setVisibility(View.GONE);
            }
        }, (long) 5000);
    }
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gallery_view_layout);
    
        ga = (Gallery) findViewById(R.id.GalleryThumbnails);
    ...
      scheduleHide ();
    ...
        imageView.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    ga.setVisibility(View.VISIBLE);
                    scheduleHide ();
                }
                return false;
            }
        });
     ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small gallery of thumbnails. When I place my mouse pointer over
I am looking for a simple picture gallery for iPhone (photo viewer). I was
I need a gallery in my application and I found this tutorial on how
I have a Gallery view in my application which is working fine. When clicking
Hey, I have Pictures that are bigger than the screen in a gallery, so
How can I dynamically add a gallery to an android app, I have: Gallery
I have a gallery I quickly coded up for a small site, and under
I have photo gallery code that does image re-sizing and thumbnail creation. I use
I have custom gallery. Gallery represents items that are frame layout. There are one
I have a gallery that's loaded via a BaseAdapter . This works fine. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.