基本代码总结

基本代码总结

 

ImageLoader应用

首先创建一个MyApplication类,继承Application

public class MyApplication extends Application{

  //重写oncreate方法

     @Override
          public void onCreate() {
                  super.onCreate();

                              ImageLoader instance = ImageLoader.getInstance();
                     ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(
                     getApplicationContext());
                     instance.init(builder.build());
                     File cacheDir = StorageUtils.getOwnCacheDirectory(
                     getApplicationContext(), "imageloader/Cache");
                     ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(
                     getApplicationContext()).memoryCacheExtraOptions(480, 800)
                    .threadPoolSize(3).diskCache(new UnlimitedDiskCache(cacheDir))
                    .threadPriority(Thread.NORM_PRIORITY - 2)
                    .denyCacheImageMultipleSizesInMemory()
                    .diskCacheSize(50 * 1024 * 1024)
                    .diskCacheFileNameGenerator(new Md5FileNameGenerator())
                    .diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
                    .tasksProcessingOrder(QueueProcessingType.LIFO)
                    .diskCacheFileCount(100).writeDebugLogs().build();
                    ImageLoader.getInstance().init(configuration);

          }

}

在Activity中配置

DisplayImageOptions options = new DisplayImageOptions.Builder()
    .showImageOnLoading(R.drawable.ic_launcher)
    .showImageForEmptyUri(R.drawable.ic_launcher)
    .showImageOnFail(R.drawable.ic_launcher).cacheInMemory(false)
    .cacheOnDisc(true).considerExifParams(true)
    .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
    .bitmapConfig(Bitmap.Config.RGB_565).considerExifParams(true)
    .delayBeforeLoading(100).resetViewBeforeLoading(true)
    .displayer(new FadeInBitmapDisplayer(100)).build();

 

使用imageloader

  ImageLoader instance = ImageLoader.getInstance();
  instance.displayImage(images[position], imageview, options);

在AndroidManifest中配置

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

在application中写清楚MyApplication的全路径名称

 

如何在自动轮播中加入小圆点

在res下创建一个drawable文件夹

创建一个xml

  <?xml version="1.0" encoding="utf-8"?>
  <shape xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="rectangle"
     >
     <corners android:radius="8dp"/>
     <solid android:color="#880000"/>
 </shape>  

在Activity中写逻辑

private void initDots() {

   dotsList = new ArrayList<ImageView>();
   linearLayout.removeAllViews();
   dotsList.clear();
   for (int i = 0; i < images.length; i++) {
   ImageView imageview=new ImageView(NewActivity.this);
   if(i==0){
        imageview.setImageDrawable(getResources().getDrawable(R.drawable.first));
   }else{
        imageview.setImageDrawable(getResources().getDrawable(R.drawable.second));
   }
   LayoutParams layoutParams=new LayoutParams(20,20);
   layoutParams.setMargins(5, 0, 5, 0);
   linearLayout.addView(imageview,layoutParams);
   dotsList.add(imageview);
  }

 

   viewpager页面切换监听中代码

   for (int i = 0; i < dotsList.size(); i++) {
         if(position==i){
           dotsList.get(i).setImageDrawable(getResources().getDrawable(R.drawable.first));
         }else{
           dotsList.get(i).setImageDrawable(getResources().getDrawable(R.drawable.second));
         }
    }

WebView应用

  WebView webview=(WebView) findViewById(R.id.webview);

   progressbar = (ProgressBar) findViewById(R.id.progressbar);


  webview.loadUrl(str);
  WebSettings settings = webview.getSettings();
  settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
  settings.setBuiltInZoomControls(true);
  settings.setDefaultFontSize(10);
  settings.setDefaultZoom(ZoomDensity.FAR);
  webview.setWebViewClient(new WebViewClient());

//进度条

  webview.setWebChromeClient(new WebChromeClient(){
   @Override
   public void onProgressChanged(WebView view, int newProgress) {
        super.onProgressChanged(view, newProgress);
        progressbar.setVisibility(View.VISIBLE);
        progressbar.setProgress(newProgress);
        if(newProgress==100){
             progressbar.setVisibility(View.GONE);
        }
       }
  });

   

@Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode==KeyEvent.KEYCODE_BACK){
    if(webview.canGoBack()){
         webview.goBack();
    }else{
         finish();
    }
   }
    return true;
 }      

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值