对图片做高斯模糊效果时,发现极少部分图片会出现左右白边。自己是没能力改进模糊算法的,就只能在其它方面下手了。
具体的做法是,在Imageview外面再嵌套一个FrameLayout,让imageview水平居中,然后通过代码,设置imageview的宽度比FrameLayou的宽度多一点,就OK了。
xml代码如下:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="200dp">
<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop"/>
</FrameLayout>
代码如下:
ImageView bgView = (ImageView) pullView.findViewById(R.id.img);
FrameLayout.LayoutParams param = (FrameLayout.LayoutParams) bgView.getLayoutParams();
param.width = mScreenWidth+6;
bgView.setLayoutParams(param);
前后效果对比: