您好,登錄后才能下訂單哦!
本篇文章為大家展示了怎么在android中實(shí)現(xiàn)視頻圖片混合輪播,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
循環(huán)添加視頻view 圖片view
for (int i = 0 ;i<beansArrayList.size();i++){ if (beansArrayList.get(i).getType()==1){ videoPlayer = new NiceVideoPlayer(this); controller = new TxVideoPlayerController(this); videoPlayer.setController(controller); videoPlayer.setUp(beansArrayList.get(i).getVideo(),null); videoPlayer.continueFromLastPosition(false); videoPlayer.setOnStart(new NiceVideoPlayer.onStart() { @Override public void start() { bannerView.startLoop(false); } }); controller.setOnRestartPause(new TxVideoPlayerController.onRestartPause() { @Override public void onStart(boolean start) { bannerView.startLoop(start); } @Override public void onRestart() { } }); GlideLoading.setImage(this,beansArrayList.get(i).getStrUrl(),controller.imageView()); viewList.add(videoPlayer); }else { ImageView img = new ImageView(this); img.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); img.setScaleType(ImageView.ScaleType.FIT_XY); img.setAdjustViewBounds(true); final int finalI = i; img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ArrayList<String> imgUrl = new ArrayList<>(); int position = 0; for (int j = 0 ;j<beansArrayList.size();j++){ if (beansArrayList.get(j).getStrUrl().equals(beansArrayList.get(finalI).getStrUrl())){ position = j ; } imgUrl.add(beansArrayList.get(j).getStrUrl()); } PreviewPhone.previewPhone(ActivityProductDetails.this,imgUrl,position,v); } }); GlideLoading.setImage(this,beansArrayList.get(i).getStrUrl(),img); viewList.add(img); } } bannerView.startLoop(true); bannerView.setOnPageSelected(new BannerView.onPageSelected() { @Override public void onNext() { if (videoPlayer != null){ if (videoPlayer.isPlaying()){ bannerView.startLoop(true); videoPlayer.pause(); } } } @Override public void onTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: bannerView.startLoop(false); break; case MotionEvent.ACTION_MOVE: bannerView.startLoop(false); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (videoPlayer.isPlaying()){ bannerView.startLoop(false); }else { bannerView.startLoop(true); } break; } } });
xml應(yīng)用
<com.zym.common.view.banner.BannerView android:id="@+id/banner" android:layout_width="match_parent" android:layout_height="200dp"> </com.zym.common.view.banner.BannerView>
輪播適配器
public class BannerAdapter extends PagerAdapter { private List<View> viewList; private int size; private final int cacheCount = 3; public BannerAdapter(List<View> viewList) { this.viewList = viewList; size = viewList.size(); } @Override public void destroyItem(ViewGroup container, int position, Object object) { if (viewList.size() > cacheCount){ container.removeView(viewList.get(position%size)); } } @Override public Object instantiateItem(ViewGroup container, int position) { ViewGroup parent = (ViewGroup) viewList.get(position%size).getParent(); if (parent != null) { parent.removeView(viewList.get(position%size)); } container.addView(viewList.get(position%size)); return viewList.get(position%size); } @Override public int getCount() { return Integer.MAX_VALUE; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; }
上述內(nèi)容就是怎么在android中實(shí)現(xiàn)視頻圖片混合輪播,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。