【问题标题】:Center crop dont work in gridlayoutmaneger Android中心裁剪在gridlayoutmanager Android中不起作用
【发布时间】:2020-04-11 07:08:48
【问题描述】:

我有使用 GridLayoutManager 和 RecyclerView 的网格视图 如您所见,网格有 3 行工作正常,[![在此处输入图像描述][1]][1]

但由于某种原因,图像视图比例类型不适用于任何项目,并且您看到的那些项目工作正常,因为分辨率已经是平方平均值 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);

这是我的网格视图项目布局代码。

<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" 机器人:adjustViewBounds =“真” 或者 fitxy 让它变得更糟 视图边界也不起作用。

如果我添加更多图像,例如 800*400 或...它将有空白

那么问题出在哪里我做错了。

【问题讨论】:

  • 您尝试过使用android:scaleType="fitXY" 吗?
  • @Biscuit 是的,它使情况变得更糟,并且破坏了其他在 centercrop 中显示良好的图像

标签: java android xml list android-recyclerview


【解决方案1】:

尝试使用 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" />

【讨论】:

  • 我之前尝试过它与 src 无关问题在其他地方
  • 你是用glide还是Picasso在imageview上设置图片?
  • 它的android默认图像视图
  • 显示在那个 ImageView 中设置图像的 java 代码,它必须在适配器的 (startPostSystem) getView() 方法中。
  • 它是 recyclerview 兄弟,它没有 getview() 方法,它有 oncreateview,其中只有代码是带有膨胀的视图
猜你喜欢
  • 2017-06-23
  • 2021-08-17
  • 2011-10-18
  • 1970-01-01
  • 1970-01-01
  • 2015-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多