我有使用 GridLayoutManager 和 RecyclerView 的 GridView 网格有 3 行,如您所见,工作正常,[![在此处输入图像描述][1]][1]
但由于某种原因, ImageView 比例类型不适用于任何项目,并且您看到的那些项目工作正常,因为分辨率已经是平方平均值 512*512,但如果您看到最后一个项目的分辨率较低,左右都有空白。
这是我的设置列表中的代码
int getori = getResources().getConfiguration().orientation;
if (getori == Configuration.ORIENTATION_PORTRAIT) {
gl = new GridLayoutManager(getBaseContext(), 3);
} else if (getori == Configuration.ORIENTATION_LANDSCAPE){
gl = new GridLayoutManager(getBaseContext(), 6);
}
gg.setHasFixedSize(true);
gg.setFitsSystemWindows(true);
gg.setLayoutManager(gl);
gg.setAdapter(startpostsystem);
这是我的网格适配器代码
@Override
public void onBindViewHolder(Grid_view holder, final int position) {
holder.im.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String getfiledop = fall[position].getAbsolutePath();
Intent is = new Intent(cm,Open_post_item.class);
is.putExtra("req",12);
cm.startActivity(is);
这是我的 GridView 项目布局代码。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="140dp">
<ImageView
android:id="@+id/imageView18"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
app:srcCompat="@drawable/sunbow100" />
我尝试使用: android:scaleType="centerCrop" 机器人:调整ViewBounds =“真” 或 fitxy 它会让事情变得更糟 View 边界也不起作用。
如果我添加更多图像,例如 800*400 或...它将有空白
那么问题出在哪里,我做错了。
最佳答案
尝试使用 android:src 代替 app:srcCompat
<ImageView
android:id="@+id/imageView18"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:src="@drawable/sunbow100" />
关于java - 中心裁剪在 gridlayoutmanager Android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61153236/