美工今天给了 启动页 还上之后 发现 图片的左右有几个像素的留白, 设置ImageView的
android:scaleType="fitXY" 可以暂时的解决问题,图片确实铺满这个ImageView控件 但是图片却被拉伸,后来发现是美工给的图片进行了高斯模糊处理,导致部分图片左右出现留白, 具体的做法是,在Imageview外面再嵌套一个FrameLayout,让imageview水平居中,然后通过代码,设置imageview的宽度比FrameLayou的宽度多一点,就OK了 在我的项目里面直接用FrameLayout布局就可以了。
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:src="@mipmap/ic_welcome" android:id="@+id/img" android:layout_width="match_parent" android:layout_height="match_parent" 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);