gallery
来源:互联网 发布:linux chattr 编辑:程序博客网 时间:2024/05/21 10:10
xml.
<LinearLayout android:layout_marginTop="5dp" android:background="@color/white" android:id="@+id/linearlayout_top" android:layout_width="fill_parent" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_height="wrap_content" android:orientation="horizontal" > <FrameLayout android:layout_width="match_parent" android:layout_height="90dp" > <com.brokerapp.widget.MyGallery android:id="@+id/huima_banner_gallery" android:layout_width="fill_parent" android:soundEffectsEnabled="false" android:keepScreenOn="true" android:fadingEdgeLength="0.0dp" android:layout_height="90dp" /> <LinearLayout android:id="@+id/huima_ll_bottomNavPoint" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom|center" android:background="#55999999" android:gravity="center" android:orientation="vertical"> <LinearLayout android:id="@+id/huima_ll_focus_indicator_container" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="right" android:orientation="horizontal" /> </LinearLayout> </FrameLayout> </LinearLayout>
MyGallery.calss
public class AdvGallery extends Gallery {<span style="white-space:pre"></span><span style="white-space:pre"></span>private static final int timerAnimation = 1;<span style="white-space:pre"></span><span style="white-space:pre"></span>private final Handler mHandler = new Handler()<span style="white-space:pre"></span>{<span style="white-space:pre"></span>public void handleMessage(android.os.Message msg)<span style="white-space:pre"></span>{<span style="white-space:pre"></span>switch (msg.what)<span style="white-space:pre"></span>{<span style="white-space:pre"></span>case timerAnimation:<span style="white-space:pre"></span>int position = getSelectedItemPosition();<span style="white-space:pre"></span>Log.i("msg", "position:"+position);<span style="white-space:pre"></span>if (position >= (getCount() - 1))<span style="white-space:pre"></span>{<span style="white-space:pre"></span>onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, null);<span style="white-space:pre"></span>} else<span style="white-space:pre"></span>{<span style="white-space:pre"></span>onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);<span style="white-space:pre"></span>}<span style="white-space:pre"></span>break;<span style="white-space:pre"></span>default:<span style="white-space:pre"></span>break;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>};<span style="white-space:pre"></span>};<span style="white-space:pre"></span><span style="white-space:pre"></span>public AdvGallery(Context context) {<span style="white-space:pre"></span>super(context);<span style="white-space:pre"></span>timer.schedule(task, 5000, 5000);<span style="white-space:pre"></span>}<span style="white-space:pre"></span><span style="white-space:pre"></span>public AdvGallery(Context context, AttributeSet attrs) {<span style="white-space:pre"></span>super(context, attrs);<span style="white-space:pre"></span>timer.schedule(task, 5000, 5000);<span style="white-space:pre"></span>}<span style="white-space:pre"></span>private final Timer timer = new Timer();<span style="white-space:pre"></span>private final TimerTask task = new TimerTask()<span style="white-space:pre"></span>{<span style="white-space:pre"></span>public void run()<span style="white-space:pre"></span>{<span style="white-space:pre"></span>mHandler.sendEmptyMessage(timerAnimation);<span style="white-space:pre"></span>}<span style="white-space:pre"></span>};<span style="white-space:pre"></span><span style="white-space:pre"></span>@Override<span style="white-space:pre"></span>public boolean onFling(MotionEvent paramMotionEvent1,<span style="white-space:pre"></span>MotionEvent paramMotionEvent2, float paramFloat1, float paramFloat2)<span style="white-space:pre"></span>{<span style="white-space:pre"></span>int keyCode;<span style="white-space:pre"></span>if (isScrollingLeft(paramMotionEvent1, paramMotionEvent2))<span style="white-space:pre"></span>{<span style="white-space:pre"></span>keyCode = KeyEvent.KEYCODE_DPAD_LEFT;<span style="white-space:pre"></span>} else<span style="white-space:pre"></span>{<span style="white-space:pre"></span>keyCode = KeyEvent.KEYCODE_DPAD_RIGHT;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>onKeyDown(keyCode, null);<span style="white-space:pre"></span>return true;<span style="white-space:pre"></span>}<span style="white-space:pre"></span><span style="white-space:pre"></span>private boolean isScrollingLeft(MotionEvent paramMotionEvent1,<span style="white-space:pre"></span>MotionEvent paramMotionEvent2)<span style="white-space:pre"></span>{<span style="white-space:pre"></span>float f2 = paramMotionEvent2.getX();<span style="white-space:pre"></span>float f1 = paramMotionEvent1.getX();<span style="white-space:pre"></span>if (f2 > f1)<span style="white-space:pre"></span>return true;<span style="white-space:pre"></span>return false;<span style="white-space:pre"></span>}<span style="white-space:pre"></span><span style="white-space:pre"></span><span style="white-space:pre"></span>@Override<span style="white-space:pre"></span>public void setUnselectedAlpha(float unselectedAlpha) {<span style="white-space:pre"></span>// TODO Auto-generated method stub<span style="white-space:pre"></span>unselectedAlpha = 1.0f;<span style="white-space:pre"></span>super.setUnselectedAlpha(unselectedAlpha);<span style="white-space:pre"></span>}}
adpter.class
//广告的适配器public class ImageAdapter extends BaseAdapter{private Context _context;private List<Drawable> adimgList;public ImageAdapter(Context context,List<Drawable> adimgList) { this._context = context; this.adimgList=adimgList;}@Overridepublic int getCount() {return Integer.MAX_VALUE;}@Overridepublic Object getItem(int position) { return position;}@Overridepublic long getItemId(int position) {return position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {ViewHolder viewHolder = null;if(convertView==null){viewHolder = new ViewHolder();ImageView imageView=new ImageView(_context);imageView.setAdjustViewBounds(true);imageView.setScaleType(ScaleType.FIT_XY);imageView.setLayoutParams(new Gallery.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));convertView = imageView; viewHolder.imageView = (ImageView)convertView; convertView.setTag(viewHolder);}else{viewHolder = (ViewHolder)convertView.getTag();}viewHolder.imageView.setImageDrawable(adimgList.get(position%adimgList.size()));return convertView;}static class ViewHolder{ ImageView imageView; }}
main.class
private void initAd() {imgList.add(this.getResources().getDrawable(R.drawable.p2));imgList.add(this.getResources().getDrawable(R.drawable.p3));ad_gallery=(MyGallery)this.findViewById(R.id.huima_banner_gallery);ad_gallery.setAdapter(new ImageAdapter(this,imgList));ad_gallery.setFocusable(true);ll_focus_indicator_container = (LinearLayout)this.findViewById(R.id.huima_ll_focus_indicator_container);InitFocusIndicatorContainer();}private void InitFocusIndicatorContainer() {for (int i = 0; i <imgList.size(); i++) {ImageView localImageView = new ImageView(this);localImageView.setId(i);ImageView.ScaleType localScaleType = ImageView.ScaleType.FIT_START ;localImageView.setScaleType(localScaleType); LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams( 24, 24); localImageView.setLayoutParams(localLayoutParams); localImageView.setPadding(5, 5, 5, 5); localImageView.setImageResource(R.drawable.adv_gallery_mark_selector); this.ll_focus_indicator_container.addView(localImageView);}}
0 0
- Gallery
- Gallery
- Gallery
- gallery
- gallery
- Gallery
- gallery
- Gallery
- Gallery
- Gallery
- Gallery
- Gallery
- Gallery
- gallery
- gallery
- Gallery
- Gallery
- gallery
- 二叉查找树的其他操作
- 常见HTTP状态(304,200等)
- MySQL基本操作
- 学习使用CBitmapButton类-----初学MFC
- 对JavaEE中session的理解
- gallery
- 页游中常见的游戏元素位置自适应浏览器大小变化之解决方案
- AxureRP7.0教程 部件详解 Droplist 下拉列表
- RFID(Radio Frequency Identification)技术,又称无线射频识别
- 【Andorid开发框架学习】之Mina开发之客户端开发
- 正益无线赵庆华:AppCan助力开发者轻装前行
- jenkins安装和使用(一)
- android学习笔记 按电源键屏幕唤醒和屏幕睡眠流程(从上层到kernel)
- Windows ListCtrl使用技巧