layout可以加入view,只要它是继承view的。
可如下的Chessboard一加入到layout中,程序崩掉。
这是为什么?package five.itcast.cn;import android.content.Context;
import android.view.View;
//棋盘
public class Chessboard extends View {
public Chessboard(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
}<?xml version="1.0" encoding="utf-8"?>
<!--You can check LayoutParams from android.view.ViewGroup-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
>
<five.itcast.cn.Chessboard
android:id="@+id/chessboard"
android:layout_width="match_parent"
android:layout_height="match_parent"
tileSize="24"
/>
</FrameLayout>
可如下的Chessboard一加入到layout中,程序崩掉。
这是为什么?package five.itcast.cn;import android.content.Context;
import android.view.View;
//棋盘
public class Chessboard extends View {
public Chessboard(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
}<?xml version="1.0" encoding="utf-8"?>
<!--You can check LayoutParams from android.view.ViewGroup-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
>
<five.itcast.cn.Chessboard
android:id="@+id/chessboard"
android:layout_width="match_parent"
android:layout_height="match_parent"
tileSize="24"
/>
</FrameLayout>
解决方案 »
- android引CGLIB 报java.lang.VerifyError
- 从运营角度讲:现在做什么android 应用软件赚钱呢????
- android webview 应用启动太慢
- android调用带soapheader的webservice
- 送分 android 平台下如何开发office
- rokon 中拖动body问题
- 如何在Android的模拟器中集成别人写好的媒体播放插件??
- android 自定义view
- 求一个使用安卓手机音频口输出正弦(方波)信号的小demo
- Android socket 编程 客户端接收的数据数据无法更新到UI上,只有当客户端与服务器断开连接时才能更新到UI上
- webkit编译错误,在线等求助!
- android中Linux内核延时函数mdelay会否进入休眠?
}第二个参数指的是自定义的组件的一些属性,就像长宽一样,你可以给组件属性,就是通过这个来传递的!这样就没问题了!你试试吧!
xml中使用自定义view,构造函数必须加上属性AttributeSet这一项!