How to make a simple image gallery for Android?

Asked

Viewed 1,165 times

1

I need to create an image gallery where I swipe to move to the next image.

I’ve been doing some research and I’ve found a lot of ways to do something similar to what I want, but I got very confused. What would be the best way to do that?

Below is an example that I would like to implement. Note that there are some balls symbolizing the amount of images:

1 answer

1


The best known is this lib here , more information about her: here

Example of use:

 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));
        }
    }
  • Very good, that’s what I was looking for! Thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.