簡體   English   中英

android.support.v7.widget.AppCompatImageView無法轉換為com.rey.material.widget.ImageView

[英]android.support.v7.widget.AppCompatImageView cannot be cast to com.rey.material.widget.ImageView

我想將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>

沒關系,這是我的錯誤點擊:

ImageView導入軟件包時,我單擊了第一個軟件包而不是通常的軟件包,這導致了此問題。 解:

更換

import com.rey.material.widget.ImageView

import android.widget.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>

在上面的代碼中,只需將<ImageView替換為<com.yourPackage.TouchImageView

TouchImageView (或其他任何類)是一個自定義類(您需要制作),應擴展android.support.v7.widget.AppCompatImageView

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM