呈现问题:找不到以下 类
Rendering problems: The following classes could not be found
我正在尝试重用另一个运行良好的应用程序中的一段代码。它是关于显示圆形图像。这是我的 XML 文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background_color"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="4dp"
card_view:cardElevation="3sp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<com.myname.myportal.utilities.RoundedImageView
android:id="@+id/category_image"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:scaleType="centerCrop"
app:border_color="@color/divider"
app:border_width="0dip"
app:is_oval="true"
app:round_background="true" />
<TextView
android:id="@+id/category_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:maxLines="1"
android:padding="5dp"
android:text=""
android:textColor="@color/text_color" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我得到的错误是
The following classes could not be found:
- com.myname.myportal.utilities.RoundedImageView
尽管我 100% 确定该文件已创建并正常工作(因为它是从另一个应用程序复制的)。如果我在文件上 Ctrl+Space
它会正确打开。我得到的唯一错误是 Cannot resolve symbol 'R'
,但我假设这是因为 XML 文件上的错误导致无法生成 R
,对吗?
首先,从原始项目中,将以下文件复制到您的项目中:
/utilities/RoundedDrawable.java
/utilities/RoundedImageView.java
/res/values/attrs.xml
然后将其添加到带有此标签的布局中:
<packagename.RoundedImageView
<!-- XML attributes --> />
这是我在测试应用程序中的示例:
<com.danielkaparunakis.Whosebugquestions.RoundedImageView
android:id="@+id/category_image"
android:layout_width="70dp"
android:src="@mipmap/ic_launcher"
android:layout_height="70dp"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:background="#000000"
android:scaleType="centerCrop"
app:border_color="#000000"
app:border_width="0dip"
app:is_oval="true"
app:round_background="true" />
我正在尝试重用另一个运行良好的应用程序中的一段代码。它是关于显示圆形图像。这是我的 XML 文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background_color"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="4dp"
card_view:cardElevation="3sp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<com.myname.myportal.utilities.RoundedImageView
android:id="@+id/category_image"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:scaleType="centerCrop"
app:border_color="@color/divider"
app:border_width="0dip"
app:is_oval="true"
app:round_background="true" />
<TextView
android:id="@+id/category_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:maxLines="1"
android:padding="5dp"
android:text=""
android:textColor="@color/text_color" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我得到的错误是
The following classes could not be found: - com.myname.myportal.utilities.RoundedImageView
尽管我 100% 确定该文件已创建并正常工作(因为它是从另一个应用程序复制的)。如果我在文件上 Ctrl+Space
它会正确打开。我得到的唯一错误是 Cannot resolve symbol 'R'
,但我假设这是因为 XML 文件上的错误导致无法生成 R
,对吗?
首先,从原始项目中,将以下文件复制到您的项目中:
/utilities/RoundedDrawable.java
/utilities/RoundedImageView.java
/res/values/attrs.xml
然后将其添加到带有此标签的布局中:
<packagename.RoundedImageView
<!-- XML attributes --> />
这是我在测试应用程序中的示例:
<com.danielkaparunakis.Whosebugquestions.RoundedImageView
android:id="@+id/category_image"
android:layout_width="70dp"
android:src="@mipmap/ic_launcher"
android:layout_height="70dp"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:background="#000000"
android:scaleType="centerCrop"
app:border_color="#000000"
app:border_width="0dip"
app:is_oval="true"
app:round_background="true" />