"snap" horizontalscrollview, like a home screen, does

I would like to know how to make horizontalscrollview “anchor” like on the home screen, which means that I have two pages in my horizontalscrollview and I can draw between each page.

+3
source share
3 answers

You have two options.

either use ViewFlipper or the Android gallery.

I prefer to use the Android gallery as it will be controlled and better suited.

In the default default Android gallery, you will find the .android.com developer site. ImageView is returned in the adapter used and in the getView () method. You manipulate your code so that it returns an inflated XML layout, for example, the following code

  class ImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;
    private Context mContext;



    public ImageAdapter(Context c) {
        mContext = c;
        TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
        mGalleryItemBackground = a.getResourceId(
                R.styleable.HelloGallery_android_galleryItemBackground, 0);
        a.recycle();
    }

    public int getCount() {
        return 5;
    }

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

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

    public View getView(int position, View convertView, ViewGroup parent) {

            convertView = LayoutInflater.from(mContext).inflate(R.layout.ownview, null);

        return convertView;
    }
}
+2

/ Android, , SwipeView, . , ViewGroup:

https://github.com/fry15/uk.co.jasonfry.android.tools

+2

you can search android.support.v4.view.ViewPager.

this thing uses Adapters with Fragments and makes life pretty simple. to start, look here:

http://android-developers.blogspot.co.nz/2011/08/horizontal-view-swiping-with-viewpager.html

0
source

Source: https://habr.com/ru/post/1792465/


All Articles