Android高斯模糊,左右有白邊

對圖片做高斯模糊效果時,發現極少部分圖片會出現左右白邊。自己是沒能力改進模糊算法的,就只能在其它方面下手了。

具體的做法是,在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);


前後效果對比:



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章