====================问题描述====================
我的SurfaceView是注册在XML中的
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray" >
<com.ada.MySurfaceView
android:id="@+id/surfaceView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout >
想实现的功能是,在activity中进行相关运算,最后得到一值,想把这个值传到SurfaceView中,
并且SurfaceView构造时要用到这个值,怎么 实现啊?????
public class CartoonActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
setContentView(R.layout.cartoon);
//在这里进行相关运算,最后得到一值,想把这个值传到SurfaceView中,
//并且SurfaceView构造时要用到这个值,怎么 实现啊?????
}
}
public class MySurfaceView extends SurfaceView implements Callback, Runnable {
public MySurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
}
@Override
public boolean onKeyDown(int key, KeyEvent event) {
return super.onKeyDown(key, event);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return true;
}
@Override
public void run() {
// TODO Auto-generated method stub
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
====================解决方案1====================
不用在XML里面放入了。 你用第一个构造函数就可以了。
可以用一个构造函数
public MySurfaceView(Context context){
}