我有一个与图片切换器适应屏幕的问题。请查看PIC 1。屏幕边缘仍然有白色的空余空间。我想要达到PIC 2的效果。没有空白空间,图片切换器完美地适应屏幕。我可以使用imageView来实现这个效果:
android:scaleType="centerCrop"
但是看起来centerCrop在imageSwitcher中不起作用。 感谢任何修复方法的建议。
更新:
这是我的XML代码: 我添加了 android:scaleType="fitXY" 但没有帮助。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageSwitcher
android:id="@+id/imageswitcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/it_intro1" >
</ImageSwitcher>
解决方案: 最终,加入了以下这行代码帮助解决问题:imageView.setScaleType(ImageView.ScaleType.FIT_XY);
public View makeView() {
ImageView imageView = new ImageView(Introduction.this);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
LayoutParams params = new ImageSwitcher.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
imageView.setLayoutParams(params);
return imageView;
}