android.support.v7.widget.AppCompatImageView 无法转换为 com.rey.material.widget.ImageView

问题描述 投票:0回答:3

我想将 URL 加载到位于与当前活动布局不同的布局中的 imageView 中。

我不知道这个 com.rey.material 包是什么以及它来自哪里。我想也许它被我导入的模板所使用。 您知道如何解决这个问题吗?

  theListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, final View view, final int pos, long l) {
            // Unfold cell first then Change Stuff inside
            // toggle clicked cell state
            ((FoldingCell) view).toggle(false);
            // register in adapter that state for selected cell is toggled
            adapter.registerToggle(pos);

            final LayoutInflater factory = getLayoutInflater();
            final View cell = factory.inflate(R.layout.cell, null);
            ImageView image = (ImageView) cell.findViewById(R.id.head_image);
            Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(image);



        }
    });

这是将所有内容包装在一起的布局:

<com.ramotion.foldingcell.FoldingCell xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:folding-cell="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    folding-cell:additionalFlipsCount="2"
    folding-cell:animationDuration="1300"
    folding-cell:backSideColor="@color/bgBackSideColor"
    folding-cell:cameraHeight="30">

    <!-- CONTENT (UNFOLDED) LAYOUT (MUST BE AT LEAST 2x times BIGGER than content layout bellow)-->
    <include layout="@layout/cell_content_layout" />

    <!-- TITLE (FOLDED) LAYOUT (MUST BE AT LEAST 2x times SMALLER than content layout above) -->
    <include layout="@layout/cell_title_layout" />

</com.ramotion.foldingcell.FoldingCell>

这是包含特定 imageView 的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="gone">
      <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/head_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                android:src="@drawable/head_image" />

        </RelativeLayout>
</LinearLayout>
java xml
3个回答
1
投票

没关系,这是我的失误:

在导入

ImageView
的包时,我点击了第一个包而不是通常的包,这导致了这个问题。 解决方案:

更换

import com.rey.material.widget.ImageView

import android.widget.ImageView

0
投票

我知道我参加聚会迟到了,但以防万一有人因为同样的问题而敲头,当我试图在我的寻呼机适配器图像中添加缩放功能时,这是一个可能对我有用的解决方案

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:visibility="gone">
  <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/head_image"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="centerCrop"
            android:src="@drawable/head_image" />

    </RelativeLayout>

在上面的代码中,只需将

<ImageView
替换为
<com.yourPackage.TouchImageView
即可。

TouchImageView(或任何其他类)是一个自定义类(您需要制作),它应该扩展android.support.v7.widget.AppCompatImageView


0
投票

替换:

android.support.v7.widget.AppCompatImageView

与:

androidx.appcompat.widget.AppCompatImageView
© www.soinside.com 2019 - 2024. All rights reserved.