2014-05-08 113 views
0

我正在尝试制作一个统一的android插件。无法创建SurfaceView

我有手动启动这样一个活动:

Activity activity = UnityPlayer.currentActivity; 
    Intent intent = new Intent(activity, VideoHelper.class); 
    activity.startActivity(intent); 

在我尝试创建一个SurfaceView的活动,但它不工作。 SurfaceView不会被创建。

活动:

public class VideoHelper extends Activity implements SurfaceHolder.Callback, OnCompletionListener 
{ 
    @Override 
    public void onCreate(Bundle bundle) 
    { 
     super.onCreate(bundle); 

     setContentView(R.layout.video_layout); 

     View view = findViewById(R.id.videoView); 
     if(view == null) 
     { 
      Log.d(LibraryMain.LogTag, "Could not create view"); 
     } 
     else 
     { 
      Log.d(LibraryMain.LogTag, "View created"); 
     } 
     //SurfaceHolder holder = view.getHolder(); 
     //holder.addCallback(this); 
    } 
    ... 
} 

video_layout.xml:

<?xml version="1.0" encoding="utf-8"?> 

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

    <SurfaceView android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:id="@+id/videoView"></SurfaceView> 

</LinearLayout> 

我总是到日志中无法创建视图。 我做错了什么?或者有没有办法通过代码创建surfaceView?

+0

请张贴使用的LinearLayout尝试创建只是SurfaceView的日志instand(更换SurfaceView的LinearLayout中,取下方向 –

+0

没有帮助,我改变了布局XML这样:<?XML版本=“1.0 “encoding =”utf-8“?> Sobraj

回答

0

我设法让它工作。

public void onCreate(Bundle bundle) 
{ 
    super.onCreate(bundle); 

    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); 
    _surface = (SurfaceView)inflater.inflate(R.layout.video_layout, null); 

    SurfaceHolder holder = _surface.getHolder(); 
    holder.addCallback(this); 

    addContentView(_surface, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
}