編輯:關於Android編程
package hold; import android.content.Context; import android.content.Intent; import android.os.Handler; import android.os.Message; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.Toast; import com.nostra13.universalimageloader.core.ImageLoader; import java.util.ArrayList; import java.util.List; import bawei.demotwo.R; import bawei.demotwo.WebViewActivity; import bean.BeanOne; import utils.CommonUtils; import utils.ImageLoaderUtils; /** * 1.類的用途 * 2.@author:Sunyubo * 3.@ 2016/11/30. */ public class ViewPagerViewHolder extends BaseViewHolder{ List<ImageView> dotList; public ViewPager vp; private LinearLayout ll; public List<BeanOne.DataBean.Ad1Bean> list; private float downx; private float downy; private long downTime; public ViewPagerViewHolder(View itemView) { super(itemView); dotList=new ArrayList<>(); vp =(ViewPager)itemView.findViewById(R.id.holder0_vp); ll =(LinearLayout)itemView.findViewById(R.id.holder0_ll); vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { for (int i = 0; i < dotList.size(); i++) { if (i == position % dotList.size()) { dotList.get(i).setImageResource(R.drawable.dot_true); } else { dotList.get(i).setImageResource(R.drawable.dot_false); } } } @Override public void onPageScrollStateChanged(int state) { } }); } @Override public void setdata(final Context context, BeanOne.DataBean dataBean) { list = dataBean.ad1; initdot(context); MyPagerAdpter ad=new MyPagerAdpter(); vp.setAdapter(ad); vp.setCurrentItem(1000); ad.setOnPagerClickListener(new OnPagerClickListener() { @Override public void setOnPagerClickListener(int position) { Toast.makeText(context, list.get(position%list.size()).ad_type_dynamic_data+"------->"+position,Toast.LENGTH_SHORT).show(); Intent i=new Intent(context,WebViewActivity.class); // i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.putExtra("url",list.get(position%list.size()).ad_type_dynamic_data); context.startActivity(i); } }); h.sendEmptyMessageDelayed(0,2000); } Handler h=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); int i=vp.getCurrentItem(); i++; vp.setCurrentItem(i); h.sendEmptyMessageDelayed(0,2000); } }; private void initdot(Context context) { h.removeCallbacksAndMessages(null); ll.removeAllViews(); dotList.clear(); for (int i = 0; i < list.size(); i++) { ImageView imageView = new ImageView(context); if (i == 0) { imageView.setImageResource(R.drawable. dot_true); } else { imageView.setImageResource(R.drawable.dot_false); } LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(6,6); params.setMargins(5, 0, 5, 0); ll.addView(imageView, params); dotList.add(imageView); } } interface OnPagerClickListener { void setOnPagerClickListener(int position); } public class MyPagerAdpter extends PagerAdapter { @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } OnPagerClickListener onPagerClickListener; public void setOnPagerClickListener(OnPagerClickListener onPagerClickListener){ this.onPagerClickListener=onPagerClickListener; } @Override public Object instantiateItem(ViewGroup container, final int position) { View view = CommonUtils.inflate(R.layout.holder_viewpager_item); ImageView img = (ImageView) view.findViewById(R.id.holder0_item_img); ImageLoader i = ImageLoader.getInstance(); i.displayImage(list.get(position % list.size()).image, img, ImageLoaderUtils.initOptions()); // Glide.with(context).load(list.get(position).image).into(img); container.addView(view); view.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: h.removeCallbacksAndMessages(null); downx = event.getX(); downy = event.getY(); downTime = System.currentTimeMillis(); break; case MotionEvent.ACTION_UP: float x = event.getX(); float y = event.getY(); if (x == downx && y == downy && System.currentTimeMillis() - downTime < 2000) { // Toast.makeText(context, "點擊", Toast.LENGTH_SHORT).show(); //viewpager點擊跳轉 if (onPagerClickListener != null) { onPagerClickListener.setOnPagerClickListener(position); } } h.sendEmptyMessageDelayed(0, 2000); break; case MotionEvent.ACTION_CANCEL: break; } return true; } }); return view; } @Override public int getCount() { return Integer.MAX_VALUE; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } } }
在android開發中對圖片處理很是頻繁,其中對圖片的顏色處理就是很常見的一種。我們經常看到一些類似美圖秀秀,美顏相機的app,為什麼那麼黑的人拍出來是確實那麼地白呢?長
一,工程圖。二,效果圖。三,代碼。RootViewController.h#import <UIKit/UIKit.h>@interface RootView
開始之前 最近學習了一下NDK的開發, 就來分享一下. 對一個新鮮事物, 我們先解決的無非就是三件事情: 是什麼?為什麼?怎麼做?.NDK簡介 (英語:native de
viewpager 在滑動的過程中是如何觸發view身上的事件的,換句話說,viewpager在滑動的過程中到底是滑動的它裡面的view,還是滑動的viewpager本身