google 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服务弹出警告对话框的问题( 详情请点击)。
准备工作已经完成下面开始写代码了:
展示图片的列表我这里使用RecycleView,activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
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.support.v7.widget.RecyclerView
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<RecyclerView.ViewHolder> {
@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);
if (isFirstTime) {//首次进入要表现第一个item的全景
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), vr);
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);
tv = (TextView) view.findViewById(R.id.content_name);
}
}
class FooterHolder extends RecyclerView.ViewHolder {//底部填充的Holder
TextView tv;
https://img-blog.csdnimg.cn/img_convert/57684307492eb1dbff1fd0361692bf38.png
https://img-blog.csdnimg.cn/img_convert/8c94c0c6ec58c5646b08f6a50a6995db.png
https://img-blog.csdnimg.cn/img_convert/280968ea767c39465e88da5d19c691dd.png
既有适合小白学习的零基础资料,也有适合3年以上履历的小搭档深入学习提升的进阶课程,涵盖了95%以上Go语言开辟知识点,真正体系化!
加入社区》https://bbs.csdn.net/forums/4304bb5a486d4c3ab8389e65ecb71ac0
(img-u2sT8TjQ-1725675572575)]
[外链图片转存中…(img-abcgIwEV-1725675572576)]
既有适合小白学习的零基础资料,也有适合3年以上履历的小搭档深入学习提升的进阶课程,涵盖了95%以上Go语言开辟知识点,真正体系化!
加入社区》https://bbs.csdn.net/forums/4304bb5a486d4c3ab8389e65ecb71ac0
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]