我正在尝试制作一个统一的Android插件。
我有一个我手动启动的活动:
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 :(得分: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));
}