思路就是这么简单,这里的全景图我们需要对应的全景图控件来显示,google vr 中有对应的全景图控件VrPanoramaView,google vr 的核心是其父类VrWidgetView,VrPanoramaView和VrVideoView是一对孪生兄弟,分别用来显示全景图和播放全景视频(google vr 视频播放即VrVideoView的使用请参考google vr 入门之制作简易的VR播放器及去除界面
控制按钮),今天我们用到的是全景图的显示功能,使用VrPanoramaView非常简单:
// 使用google vr VrPanoramaView 添加的
compile ‘com.google.vr:sdk-audio:1.40.0’
compile ‘com.google.vr:sdk-base:1.40.0’
compile ‘com.google.vr:sdk-panowidget:1.40.0’
我们要用的VrPanoramaView在sdk-panowidget库中,这里使用1.40.0版本是为了去除android 7.0手机没有使用google vr服务d出警告对话框的问题( 详情请点击)。
准备工作已经完成下面开始写代码了:
展示图片的列表我这里使用RecycleView,activity_main.xml
xmlns:android=“http://schemas.android.com/apk/res/android” xmlns:tools=“http://schemas.android.com/tools” android:id="@+id/activity_main" android:layout_width=“match_parent” android:layout_height=“match_parent” tools:context=“com.qj.vrpanoramaviewlist.MainActivity”>
android:id="@+id/recycleview" android:layout_width=“match_parent” android:layout_height=“match_parent”/> mRecyclerView = (RecyclerView) findViewById(R.id.recycleview); //全景图控件初始化 vrPanoramaView = new VrPanoramaView(this); vrPanoramaView.setStereoModeButtonEnabled(false);//眼镜模式按钮禁掉 vrPanoramaView.setFullscreenButtonEnabled(false); //全屏模式按钮禁掉 vrPanoramaView.setInfoButtonEnabled(false); //信息按钮禁掉 vrPanoramaView.setTouchTrackingEnabled(true); //开启手触模式 options = new VrPanoramaView.Options(); options.inputType = VrPanoramaView.Options.TYPE_MONO; 为RecycleView准备数据,设置适配器 //准备数据,这里模拟假数据 mDatas = new ArrayList(); for (int i = ‘A’; i < ‘M’; i++) { mDatas.add(String.valueOf((char) i)); } mSize = mDatas.size(); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mAdapter = new HomeAdapter(); mRecyclerView.setAdapter(mAdapter); 看看HomeAdapter的内容: class HomeAdapter extends RecyclerView.Adapter @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == PANORAMA_ITEM) { return new VrPanoramaViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_panorama, parent, false)); } else { return new FooterHolder(LayoutInflater.from(mContext).inflate(R.layout.item_footer, parent, false)); } } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (mSize - position > 2) { VrPanoramaViewHolder h = (VrPanoramaViewHolder) holder; h.tv.setText(mDatas.get(position)); h.iv.setBackgroundResource(plan[position]); if (isFirstTime) {//首次进入要显示第一个item的全景 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), vr[0]); vrPanoramaView.loadImageFromBitmap(bitmap, options); h.iv.addView(vrPanoramaView); currentPos = 0; isFirstTime = false; } } else if (position == mSize - 1) { FooterHolder h = (FooterHolder) holder; h.tv.setText(“到底啦…”); } Log.e(TAG, "onBindViewHolder: " + position); } @Override public int getItemCount() { return mSize; } @Override public int getItemViewType(int position) { if (mSize - position > 2) { return PANORAMA_ITEM;//全景图类型的item } else { return FOOTER_ITEM;//底部填充的两个item } } class VrPanoramaViewHolder extends RecyclerView.ViewHolder {//全景图的Holder frameLayout iv; TextView tv; public VrPanoramaViewHolder(View view) { super(view); iv = (frameLayout) view.findViewById(R.id.iv_content); der extends RecyclerView.ViewHolder {//全景图的Holder frameLayout iv; TextView tv; public VrPanoramaViewHolder(View view) { super(view); iv = (frameLayout) view.findViewById(R.id.iv_content); 欢迎分享,转载请注明来源:内存溢出
评论列表(0条)