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

时间:2018-01-17 10:07:40

标签: java android xml android-viewpager android-adapter

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

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

我认为这很容易,但我需要帮助。

这样的事情:

enter image description here

由于

1 个答案:

答案 0 :(得分: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);