viewpager中的图片是url的话,
for (int i=0;i<banner.size();i++) { String img = banner.get(i).getImg(); String url = banner.get(i).getUrl(); list_url.add(url); ImageView image=new ImageView(MainActivity.this);// Picasso.with(MainActivity.this).load(img).into(image);// list_image.add(image);// 这三个方法,就直接添加到集合; ImageView image1=new ImageView(MainActivity.this); image1.setImageResource(R.drawable.sector_dra); list_image1.add(image1); line.addView(image1); image1.setPadding(10,0,10,0); }
viewpager的无限轮播使用,首先你要先弄适配器:重写四个方法:
class myadpter extends PagerAdapter{ @Override public int getCount() { return Integer.MAX_VALUE;//返回最大值,说明集合中图片的最大值! } @Override public boolean isViewFromObject(View view, Object object) { return view==object; } @Override public Object instantiateItem(ViewGroup container, final int position) { //如果只有两张图片的话,就必须抛个异常,因为图片太少
ImageView imageView = list_image.get(position%list_image.size()); try { container.addView(imageView); return imageView; }catch (Exception e){ } imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(MainActivity.this,Next.class); intent.putExtra("position",position%list_image.size()); intent.putStringArrayListExtra("list", (ArrayList<String>) list_url); startActivity(intent); } }); return imageView; } @Override public void destroyItem(ViewGroup container, int position, Object object) {
//如果只有两张图片,就不需要在这里写方法;
// ImageView imageView = list_image.get(position%list_image.size());// container.removeView(imageView); } }
无限轮播需要在主线程发送:
h1.sendEmptyMessageDelayed(0,1000);
然后再
android.os.Handler h1=new android.os.Handler(){//记住导os包 @Override public void handleMessage(Message msg) { if(msg.what==0) { int currentItem = viewpager.getCurrentItem(); currentItem++; viewpager.setCurrentItem(currentItem); h1.sendEmptyMessageDelayed(0,1000); } super.handleMessage(msg); } }; 对于shape的使用 在res下drawable 里 建一个shape:<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <size android:height="10dp" android:width="10dp" ></size> <solid android:color="#fff" ></solid> </shape>然后再建一个selector<selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_selected="true" android:drawable="@drawable/shape_true" ></item> <item android:state_selected="false" android:drawable="@drawable/shape_false" ></item> </selector>
webview里显示进度条:webview.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { // 加载完毕 closeDialog(newProgress); } else { openDialog(newProgress); } super.onProgressChanged(view, newProgress); } private void openDialog(int newProgress) { if (dialog == null) { dialog = new ProgressDialog(Next.this); dialog.setTitle("正在加载"); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog.setProgress(newProgress); dialog.show(); } else { dialog.setProgress(newProgress); } } private void closeDialog(int newProgress) { if (dialog != null && dialog.isShowing()) { dialog.dismiss(); dialog = null; } } });