这种问题的首要原因是放置的图片格式大小不同。
我们可以通过不同的item布局观察其中的变化
GridVIew的layout如下
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<GridView
android:id="@+id/grid_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="2"
/>
首先贴一下正常效果:
1.wrap_content
这种必会出问题
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
/>
</LinearLayout>
效果就是下图,整的跟瀑布流一样
2.仅设置item中ImageView的scaleType
根据不同的设置,有不同的表现。
fitcenter 无变化
fitXY|center|centerCrop 间距问题能够解决,但同时图片会变形且item长度过长
3.设置ImageView为固定长度300dp
显示正常。
结论:我们从正常效果图可以看到,第二张图片的宽度与其他图片有显著区别。
因此,在GridView中尽量放的图片格式大小相同,可以减少一些问题的出现。
本文地址:https://blog.csdn.net/kisaragi_yu/article/details/107445436
如对本文有疑问, 点击进行留言回复!!
Android安卓水滴屏适配状态栏图标(图标过多时显示一个点)
android studio使用Flutter创建web项目
android如何使用taskAffinity属性对任务栈操作控制
android对PDF文件的操作(上传、预览、下载和转存相册)
Android通过代码批量生成字符图标用于给输入法显示状态栏的图标
网友评论