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

  • SEARCH
  • Home
  • 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 7050065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:05:53+00:00 2026-05-28T03:05:53+00:00

I would like to add two gallery view to my app. To be clear

  • 0

I would like to add two gallery view to my app. To be clear with my question as it shows in the image below. I would like to add another horizontal scroll view below the image view that will also display images and function exactly as the one above.

Here is the code that I’ve come up with so far. It’s the same example as the developer samples. Just some minor changes to it.

public class Gallery2DemoActivity extends Activity {
private Gallery gallery,gallery1;
private ImageView imgView;

private Integer[] Imgid = {
        R.drawable.a_1, R.drawable.a_2, R.drawable.a_3, R.drawable.a_4, R.drawable.a_5, R.drawable.a_6, R.drawable.a_7
};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    gallery = (Gallery) findViewById(R.id.examplegallery);
    gallery.setAdapter(new AddImgAdp(this));

    gallery1 = (Gallery)findViewById(R.id.examplegallery1);
    gallery1.setAdapter(new AddImgAdp(this));

    imgView = (ImageView)findViewById(R.id.ImageView01);    
    imgView.setImageResource(Imgid[0]);


     gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
            imgView.setImageResource(Imgid[position]); 
        }
    });

}

public class AddImgAdp extends BaseAdapter {
    int GalItemBg;
    private Context cont;

    public AddImgAdp(Context c) {
        cont = c;
        TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
        GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
        typArray.recycle();
    }

    public int getCount() {
        return Imgid.length;
    }

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

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

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imgView = new ImageView(cont);

        imgView.setImageResource(Imgid[position]);
        imgView.setLayoutParams(new Gallery.LayoutParams(110, 100));
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);
        imgView.setBackgroundResource(GalItemBg);

        return imgView;
    }
}

}

Below is my XML file. Which is pretty straight forward and simple.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Gallery
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/examplegallery"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<ImageView
    android:id="@+id/ImageView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
<Gallery
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/examplegallery1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
</LinearLayout>

Can’t I set two gallery Views to one AddImg adapter ?

Where am I going wrong ? The Second Horizontal Scroll View is not showing up.

How can I work around this problem ?

  • 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-05-28T03:05:53+00:00Added an answer on May 28, 2026 at 3:05 am

    I thinks that the problem is in your layout implementation. Try setting android:layout_weight=”1″ on the image view. I think that will solve the issue. Modified layout is provided below:

     <?xml version="1.0" encoding="utf-8"?>
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >
    
                <Gallery
                    android:id="@+id/examplegallery"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />
    
                <ImageView
                    android:id="@+id/ImageView01"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" 
                    android:layout_weight="1"/>
    
                <Gallery
                    android:id="@+id/examplegallery1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />
    
            </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two doubts: 1. I would like to add some client side support
I would like to add a GestureDetector to all views (view groups) of an
I would like to add rows to DataGridView from two seperate threads. I tried
I have two XML trees and would like to add one tree as a
I would like to add two lines after the first string search. I am
I would like to add two vectors with different lengths in Matlab or Octave.
I've got a problem I would like to add two overlays on both side
I would like to add two compiler flags, one for ARC (-fno-objc-arc) and one
I would like to add two additional xml namespaces to the <HTML> element in
i would like to add a character to a text-box that separates two characters

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.