0

I have a viewPager with infinite loop, but i want to set a border to highlight the current image.

In my main activity i've the adapterPageAdapter and the custom ViewPager (that is clickable).

I think that is easy, but i need help.

Something like this:

enter image description here

Thanks

Roshna Omer
  • 687
  • 1
  • 11
  • 20
Joel Garcia
  • 61
  • 1
  • 12
  • For this type of task, you can use `OnPageChangeListener` method's `onPageSelected`. onPageSelected returns the page number of viewpager which is currently visible to user. – Aditya Jan 17 '18 at 10:15
  • to give border to imageview simply set the background and padding – Zayid Mohammed Jan 17 '18 at 10:22

1 Answers1

0
> Place image view inside another layout set the background color of
> parent layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/border"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
    android:padding="1dp">

    <ImageView
        android:id="@+id/imageViewImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:foregroundGravity="center_horizontal"/>
</RelativeLayout>
> inside PagerAdapter instantiateItem method when you are setting bitmap
> to imageView, also set backgroud color to layout.
final RelativeLayout border =  (RelativeLayout) view.findViewById(R.id.border);
border.setBackgroundColor(Color.RED);
jessica
  • 1,700
  • 1
  • 11
  • 17