How to make a simple image gallery for Android?

1

I need to create an image gallery where I slide my finger to move to the next image.

I've been researching and found several ways to do something similar to what I want, but I was very confused. What would be the best way to do this?

Here's an example I'd like to implement. Note that there are some balls symbolizing the amount of images:

    
asked by anonymous 21.03.2016 / 23:57

1 answer

1

The best known is this here , more information about it: here

Usage example:

 public class AdapterCircleIndicator extends FragmentStatePagerAdapter {

        private int mCount;

        public AdapterCircleIndicator(FragmentManager fm,int number) {
            super(fm);
            this.mCount = numberPage;
        }

        @Override
        public Fragment getItem(int position) {
            Fragment f = new Fragment();
            f = new SeuFragment();
            return f;
        }

        @Override
        public int getCount() {
            return mCount;
        }    
    }

Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <com.viewpagerindicator.CirclePageIndicator
            android:id="@+id/indicator"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:padding="5dip"
            app:fillColor="@color/blue"
            app:radius="@dimen/dp5"
            app:strokeColor="@android:color/white"
            app:strokeWidth="@dimen/dp2"
            android:layout_marginBottom="@dimen/dp15"/>
    </LinearLayout>
</LinearLayout>

Activity:

public class NOMEACTIVITY extends AppCompatActivity {
    @Bind(R.id.pager)
    ViewPager mPager; // equivale a : ViewPager mPager = (ViewPager) findViewById(...);
    @Bind(R.id.indicator)
    CirclePageIndicator mIndicator;
    AdapterCircleIndicator mAdapter;
    @Bind(R.id.appBar)
    Toolbar toolbar;
    @BindColor(R.color.blue)
    int colorFill;
    @BindColor(R.color.colorTextDefault)
    int colorStroke;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.seu_layout);

        mAdapter = new AdapterCircleIndicator(getSupportFragmentManager());
        mPager.setAdapter(mAdapter);
        mIndicator.setViewPager(mPager);
        mIndicator.setStrokeColor(colorStroke);
        mIndicator.setFillColor(colorFill);


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.yellow_dark));
        }
    }
    
22.03.2016 / 01:58