gpt4 book ai didi

android自定义 View 在虚拟机中有错误

转载 作者:行者123 更新时间:2023-11-30 03:56:01 24 4
gpt4 key购买 nike

我写了一个简单的扩展 View 类,代码如下:

public class MyView extends View
{

public MyView(Context context)
{
super(context);
}

public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}

protected void OnDraw(Canvas canvas)
{
super.onDraw(canvas);
}
}

XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >


<com.main.sufaceview.MyView
android:id="@+id/myview"
android:layout_width="300dp"
android:layout_height="300dp"
android:background="@drawable/tt"/>

</RelativeLayout>

进入虚拟机时。它显示了分割: enter image description here

这是为什么?我认为自定义 View 应该很容易。我没有添加其他代码,它有错误。编辑:logcat 显示: enter image description here

最佳答案

我认为您至少需要另一个构造函数,这是我在其他帖子中读到的内容。

public MyView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

关于android自定义 View 在虚拟机中有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13358532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com