1

現在、SurfaceView をテストしようとしています。プレビューに表示されます。私のカスタムSurfaceView(「RollView」)の名前が付いた灰色の背景が表示されます。毎回私はそれをテストしようとします。すぐにクラッシュします。com.hovanky.roll.RollView xml タグを削除すると、機能します。しかし、私はサーフェスビューを失います。私は何を間違っていますか?

xml で、カスタム SurfaceView に入れました

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


<com.hovanky.roll.RollView
        android:id="@+id/rollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>


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

</RelativeLayout>
</FrameLayout>

私の活動では、それが活動を拡張します。SurfaceView にハンドルを渡します

 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mRollView = (RollView) findViewById(R.id.rollview);

次に、カスタム SurfaceView のスケルトンを作成します。

 class RollView extends SurfaceView implements SurfaceHolder.Callback {
 private SurfaceHolder holder;

 public RollView(Context context) {
    super(context);
    holder= getHolder();
    holder.addCallback(this);
}


@Override
public void surfaceCreated(SurfaceHolder holder) {
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
4

1 に答える 1

1

RollView クラスを次のように変更します。

    class RollView extends SurfaceView implements SurfaceHolder.Callback {
     private SurfaceHolder holder;

     public RollView(Context context) {
        super(context);
        holder= getHolder();
        holder.addCallback(this);
    }

    public RollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }
   //your code here...
于 2013-01-04T16:45:07.283 に答える