score:1

Accepted answer

you can do a workaround.

instead of adding a viewpager you simply add a view extended by baseadapter.

in there you add a view with horizontallscroll. the click event you can trigger with the id of the corresponding view.

with this example you see how horizontall implement: http://examples.javacodegeeks.com/android/core/ui/horizontalscrollview/android-horizontalscrollview-example/

please take notice that you must set your child width (in your case the picture) to match_parent. use a layout (that have match_parent) and in this layout you place your picture with wrap_content, for none stretching the picture.

edit 1:

first you create your horizontalscrollview layout like the following:

    <?xml version="1.0" encoding="utf-8"?>
    <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

    <horizontalscrollview
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margintop="50dp" >

        <linearlayout
            android:id="@+id/hori_place_holder"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >
        </linearlayout>
    </horizontalscrollview>
</linearlayout>

now you create a adapterview for your layout that you want to place in the linearlayout

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <imageview
        android:id="@+id/imageview1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/yourimage" />

</linearlayout>

now in your code you dynamically create and add the adapterview (like you have) to the linearlayout from your horizontalscrollview.

edit 2

public class horizontalscrollviewadapter extends baseadapter {
        ...
        @override
        public view getview(int pos, view convertview, viewgroup parent) {
            view v = convertview;
            imageview img_menu;
            if(v==null){
            inflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service);
            v = inflater.inflate(r.layout.horiscvi, parent, false);
            }
            // at this you must add your customeviewlayout
            return v;
        }
    }

and the adapter for customeview

public class customeviewadapter extends baseadapter {
    ...
    @override
    public view getview(int pos, view convertview, viewgroup parent) {
        view v = convertview;
        imageview img_menu;
        if(v==null){
        inflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service);
        v = inflater.inflate(r.layout.list_makanan, parent, false);
        }
        img_menu = (imageview)v.findviewbyid(r.id.picture_menu_on_listview);
        v.addview(img_menu);
        return v;
    }
}

edit 3

ok, now in your adapterview you have a section thats looking like the following:

arraylist<sitecontentdata> sitecontentdata = new arraylist<sitecontentdata>();
        sitecontentdata.add(new sitecontentdata("one", "yourpicone"));
        sitecontentdata.add(new sitecontentdata("two", "yourpictwo"));
        sitecontentdata.add(new sitecontentdata("three", "yourpicthree"));
        sitecontentdata.add(new sitecontentdata("four", "yourpicfour"));

        horizontalscrollview = ((horizontalscrollview) findviewbyid(r.id.horizontalscrollview1));
        sitepreview = ((linearlayout) findviewbyid(r.id.hori_linear));

        for (sitecontentdata sitecontdata : sitecontentdata)
        {
            view convertview;
            layoutinflater inflatercustomeshow =
                    (layoutinflater) getapplicationcontext().getsystemservice(
                            context.layout_inflater_service);
            convertview = inflatercustomeshow.inflate(r.layout.customeimage, null);
            view sitepreviewview =
                    sitecontentpreview.getview(getapplicationcontext(), convertview, sitecontdata);

            sitepreview.addview(sitepreviewview);
        }

in this you initialize your scrollview with the linearlayout inside of this. specially you adding the customeview inside of the linearlayout. the sitecontentdata is just a pojo thats hold two strings, the first is some sample text and the second is the path to the image in your project.

and the sitecontentpreview looks like this:

public class sitecontentpreview
{
    public static view getview(context context, view convertview, sitecontentdata sitecontent)
    {
        view result = convertview;
        if (result == null)
        {
            layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);
            result = inflater.inflate(r.layout.customeimage, null);
        }

        textview sitenumber = ((textview) result.findviewbyid(r.id.custome_imageview_text));
        imagebutton siteimage = ((imagebutton) result.findviewbyid(r.id.custome_image_view));
        if (sitecontent != null)
        {
            sitenumber.settext(sitecontent.getsitenumber());
            siteimage.setimageresource(integer.parseint(sitecontent.getsitecontentframe()));
        }

        return result;
    }
}

just simple assigning.

that's all.

the horizontalscrollview layout you are right and here is the layout for the customeviewimage:

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <imageview
        android:id="@+id/custome_image_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <textview
        android:id="@+id/custome_imageview_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="textview" />

</linearlayout>

that's all. enjoy. hope you achieve what you want.

public class sitecontentdata
{
private string sitenumber;
private string sitecontentframe;

public sitecontentdata(string sitenumber, string sitecontentframe)
{
this.sitenumber = sitenumber;
this.sitecontentframe = sitecontentframe;
}

public string getsitenumber()
{
return sitenumber;
}

public string getsitecontentframe()
{
return sitecontentframe;
}

}

Related Query

More Query from same tag