我收到运行时错误,说不能将RelativeLayout强制转换为我的类,即使我的类派生自RelativeLayout。
这是我的班级:
public class RippleBackground extends RelativeLayout{
....
这是发生崩溃的主要活动中的一行:
final RippleBackground rippleBackground=(RippleBackground)findViewById(R.id.embeddedContent);
这是布局内容:
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/textView"
android:layout_alignParentStart="true"
android:id="@+id/embeddedContent"
app:rb_color="#0099CC"
app:rb_radius="32dp"
app:rb_rippleAmount="4"
app:rb_duration="3000"
app:rb_scale="6"
android:layout_marginTop="71dp"></RelativeLayout>
错误是:
"android.widget.RelativeLayout cannot be cast to RippleBackground"
答案 0 :(得分:1)
<com.mypackage.RippleBackground
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/textView"
android:layout_alignParentStart="true"
android:id="@+id/embeddedContent"
app:rb_color="#0099CC"
app:rb_radius="32dp"
app:rb_rippleAmount="4"
app:rb_duration="3000"
app:rb_scale="6"
android:layout_marginTop="71dp"></com.mypackage.RippleBackground>