我在谷歌和本网站上搜索和推荐。但我没有得到正确答案。在我的手机屏幕尺寸中,网格视图是可以的。但对于平板电脑屏幕尺寸,网格视图会发生混乱。
gridview.xml的代码
<GridView
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="8dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="8dp">
MainActivity.java的代码
gridView = (GridView) findViewById(R.id.grid_view);
gridView.setAdapter(new ImageAdapter(this));
ImageAdapter.java的代码
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(220, 210));
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(imageID[position]);
return imageView;
}
答案 0 :(得分:0)
Recycler视图功能更强大。您可以使用GridLayoutManager进行尝试。
点击此处。
https://inducesmile.com/android/android-gridlayoutmanager-with-recyclerview-in-material-design/