在 ViewPager 的选定图像上设置边框

Set border on the selected image of a ViewPager

我有一个无限循环的viewPager,但我想设置一个边框来突出显示当前图像。

在我的主要 activity 中,我有适配器PageAdapter 和自定义 ViewPager(可点击)。

我觉得这很容易,但我需要帮助。

像这样:

谢谢

> 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);