Android仿腾讯视频广告图片轮播效果代码
程序员文章站
2022-03-01 13:49:32
...
本例子是利用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