Question

I am trying to use a Gallery View (knowing its deprecated) as an horizontal GridView. It's OK, but now i want to make it display only one item at the time, meaning each item fills the width of the parent.

Here is my XML (minimalistic at this time, just a LinearLayout) :

<LinearLayout
        android:id="@+id/profile"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/galleryLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/gallerylabeltext"
            android:layout_marginBottom="10dp"
            android:textSize="@dimen/small_text_size" />

        <Gallery
            android:id="@+id/mygallery"
            android:layout_width="fill_parent"
            android:layout_height="80dp"
            android:gravity="center" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="@android:color/darker_gray" />

</LinearLayout>

How can i achieve that ? Extending the Gallery Class ? In the XML ?

Thanks in advance for your help.

Was it helpful?

Solution

try this adapter for gallary,

public class ImageAdapter extends BaseAdapter {

        private Context mContext;

        public ImageAdapter(Context c) {
            mContext = c;
            aQuery = new AQuery(c); 
        }

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

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

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

        @SuppressWarnings("deprecation")
        public View getView(final int pos, View arg1, ViewGroup arg2) {
            ImageView i = new ImageView(mContext);
            i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            i.setScaleType(ScaleType.FIT_XY);
            i.setImageResource(myImageList[pos]);
            return i;
        }
    }

OTHER TIPS

you can try to use "RelativeLayout" replace the "LinearLayout" in XML ,i have once to use Gallery display only one item at the time

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top