google vr 入门之VrPanoramaView制作全景图列表(1)

展示图片的列表我这里使用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[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);

tv = (TextView) view.findViewById(R.id.content_name);

}

}

class FooterHolder extends RecyclerView.ViewHolder {//底部填充的Holder

TextView tv;

public FooterHolder(View view) {

super(view);

tv = (TextView) view.findViewById(R.id.footer_tv);

}

}

}

对RecycleView添加滚动监听:



既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!

加入社区》https://bbs.csdn.net/forums/4304bb5a486d4c3ab8389e65ecb71ac0

(img-r5V77i1N-1725675345398)]

[外链图片转存中...(img-ckMJv0U8-1725675345398)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Go语言开发知识点,真正体系化!

加入社区》https://bbs.csdn.net/forums/4304bb5a486d4c3ab8389e65ecb71ac0

相关推荐
jimumeta8 小时前
实时渲染技术如何助力3D虚拟展厅?
3d·vr·虚拟展厅·实时渲染·3d展厅
sxy1993sxy20184 天前
AR、VR、MR、XR - 20241110
ar·vr·mr
凯子坚持 c5 天前
AIGC与虚拟现实(VR)的结合与应用前景
aigc·vr
小生云木5 天前
VR的左右眼渲染方法
vr
MediaTea6 天前
Pr 视频过渡:沉浸式视频 - VR 随机块
vr
MediaTea6 天前
Pr 视频过渡:沉浸式视频 - VR 色度泄漏
音视频·vr
MediaTea7 天前
Pr 视频过渡:沉浸式视频 - VR 默比乌斯缩放
vr
道可云7 天前
道可云人工智能&元宇宙每日资讯|2024国际虚拟现实创新大会将在青岛举办
大数据·人工智能·3d·机器人·ar·vr
MediaTea7 天前
Pr 视频过渡:沉浸式视频 - VR 球形模糊
vr
花生糖@7 天前
VR 创业之路:从《I Expect You To Die》到未来展望
创业创新·vr·创业