一、问题:
自己自定义了一个surfaceview,在onMeasurea方法中设置该控件的高度,发现一旦超过8192就不会回调surfaceCreated( )函数,是什么原因造成的?一直想不通为什么会不回调...有这个限制吗?
二、测试的例子:
这里把surfaceview放到scrollview中,可以上下滑动查看。(把scrollview去掉也出现同样的问题)
当高度大于8192时,查看log打印的信息,发现没有调用surfaceCreated( )。
**1、自定义的TestSurfaceView.java**
package com.hebei.textviewdemo6;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class TestSurfaceView extends SurfaceView implements SurfaceHolder.Callback{
public TestSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
SurfaceHolder holder = getHolder();
holder.addCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
Log.d("surfaceCreated", "created");
Log.d("surfaceCreated", "widht = "+this.getWidth()+" height = "+this.getHeight());
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
Log.d("surfaceChanged", "changed");
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
Log.d("surfaceDestoryed", "destoryed");
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = 8193;
Log.d("onMeasure", "Width = "+width+" Height = "+height);
setMeasuredDimension(width, height);
}
}
**2、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"
tools:context="com.hebei.textviewdemo6.MainActivity" >
<ScrollView
android:id="@+id/scrollview_demo6"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#FF0000"
android:fadingEdge="vertical"
android:scrollbars="vertical" >
<com.hebei.textviewdemo6.TestSurfaceView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
</RelativeLayout>
**3、MainActivity.java**
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("onCreate", "create");
}
}