Android仿腾讯视频广告图片轮播效果代码
2015-07-06 10:49:18 By: shinyuu
本例子是利用Gallery制作的一个图片轮播的例子、要想使用ViewPager的哥们可以绕道了、仿腾讯视频的最新视频信息的轮播显示、点击时可跳转、能无限循环自动滑动和手动滑动、动画切换流畅、有少量注释、编译版本2.3.3(高版本上依然可以正常运行的、没有任何问题)、编码GBK、效果图如下
XML代码
<FrameLayout android:layout_width="fill_parent" android:layout_height="257dip" > <com.demo.MyGallery android:id="@ id/banner_gallery" android:layout_width="fill_parent" android:layout_height="257dip" android:background="#000" android:fadingEdgeLength="0.0dp" android:keepScreenOn="true" android:soundEffectsEnabled="false" /> <LinearLayout android:id="@ id/ll_bottomNavPoint" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom|center" android:background="#00000000" android:gravity="center" android:orientation="vertical" android:paddingBottom="5dp" > <LinearLayout android:id="@ id/ll_focus_indicator_container" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal" /> </LinearLayout> </FrameLayout>
Java代码onCreate
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); InitImgList(); ll_focus_indicator_container = (LinearLayout) findViewById(R .id.ll_focus_indicator_container); InitFocusIndicatorContainer(); gallery = (MyGallery) findViewById(R.id.banner_gallery); gallery.setAdapter(new ImageAdapter(this)); gallery.setFocusable(true); gallery.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int selIndex, long arg3) { // 修改上一次选中项的背景 selIndex = selIndex % imgList.size(); ImageView preSelImg = (ImageView) ll_focus_indicator_container .findViewById(preSelImgIndex); preSelImg.setImageDrawable(MainActivity.this.getResources() .getDrawable(R.drawable.ic_focus)); // 修改当前选中项的背景 ImageView curSelImg = (ImageView) ll_focus_indicator_container .findViewById(selIndex); curSelImg.setImageDrawable(MainActivity.this.getResources() .getDrawable(R.drawable.ic_focus_select)); preSelImgIndex = selIndex; } public void onNothingSelected(AdapterView<?> arg0) { } }); Log.i("msg", "260px:" px2dip(this, 260)); }
最后给贴上Demo的源代码、希望对大家有用、有兴趣的哥们可以下载看看
源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1gdo3Hkf 密码: jhqf
若资源对你有帮助、浏览后有很大收获、不妨小额打赏我一下、你的鼓励是维持我不断写博客最大动力
想获取DD博客最新代码、你可以扫描下方的二维码、关注DD博客微信公众号(ddblogs)
或者你也可以关注我的新浪微博、了解DD博客的最新动态:DD博客官方微博(dwtedx的微博)
如对资源有任何疑问或觉得仍然有很大的改善空间、可以对该博文进行评论、希望不吝赐教
为保证及时回复、可以使用博客留言板给我留言: DD博客留言板(dwtedx的留言板)
感谢你的访问、祝你生活愉快、工作顺心、欢迎常来逛逛
shinyuu 2016-09-10 11:12:05 4 评 | 回复
@[email protected]:PagerView 好像是在超过3张的时候会出问题,到adapter里面处理一下就好了