java - 中心裁剪在 gridlayoutmanager Android 中不起作用

标签 java android xml list android-recyclerview

我有使用 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/

相关文章:

java - Maven依赖版本不一样

java - 我的 UI 中的 KeyListener NullPointerAcception,为什么是 JTextField.setText ("");不工作?

java - Svn从分支合并到主干而不删除主干(或其历史记录)

c# - 在 Unity Android 和 iOS 部署中从收件箱读取短信

java - 使用 Stax 在 XML 文件中搜索特定字符串

java - 如何让计时器在后台运行以在一定时间后执行操作?

android - Android 日志条目在内存中保留多长时间

android - 重置 GoogleAuthUtil,以便再次获得许可

android - 从上到下移动 TextView

node.js - 在 node.js 中解析大型 xml 文件(1G+)