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