美文网首页Java_StudyAndroid知识Android技术知识
安卓之项目实战经验总结(2)

安卓之项目实战经验总结(2)

作者: 大白栈 | 来源:发表于2016-09-26 11:59 被阅读169次

    1、时间戳转换问题
    我们在开发的时候,我们会把服务器返回的时间戳转为年月日时分秒等格式,但是在转换的时间会发现时间和服务器的时间好像对应不起来,原因是因为我们没有设置时区,sdf.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));这句代码很重要

    public static String timeStamp2Date(String seconds, String format) {
        if (seconds == null || seconds.isEmpty() || seconds.equals("null")) {
            return "";
        }
        if (format == null || format.isEmpty())
            format = "yyyy-MM-dd";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
        return sdf.format(new Date(Long.valueOf(seconds + "000")));
    }
    

    2、防止测试人员或者用户对按钮重复点击

    private static long lastClickTime;
    
    public synchronized static boolean isFastRepeatClick() {
        long time = System.currentTimeMillis();
        if (time - lastClickTime < 500) {
            return true;
        }
        lastClickTime = time;
        return false;
    }
    

    3、使用Glide图片变形的问题

       public static void Glide_iamge(Context mContext, String url, ImageView imageView) {
            Glide.with(mContext)
                    .load(url)
                    .asBitmap()
                    .error(R.mipmap.ic_default_fliter_img)
                    .placeholder(R.mipmap.pic_loading)
                    .centerCrop()
                    .into(new MyBitmapImageViewTarget(imageView));
           }
    

    4、使用Glide图片变绿的问题

    第一种解决方案:

    Glide.with(a).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(i);

    第二种解决方案:

     * Created by zhaoyong on 2016/1/26. 
     * 增加图片清晰度 
     */  
    public class GlideConfiguration implements GlideModule{  
        @Override  
        public void applyOptions(Context context, GlideBuilder builder) {  
            builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);  
        }  
      
        @Override  
        public void registerComponents(Context context, Glide glide) {  
      
        }  
    }  
    
    然后在AndroidManifext中配置:
    <meta-data  
        android:name="com.xxx.xxx.xxx.GlideConfiguration"  
        android:value="GlideModule"/>  
    

    5、取消网络请求

    // Retrofit 取消网络请求:
    Call<List<Contributor>> call =  gitHubService.repoContributors("square", "retrofit");
    call.enqueue(   
         );
    // or...call.execute();
    // later...call.cancel();
    //Volley取消网络请求:
    VolleyHelper.getInstance().getRequestQueue().cancelAll("POST");
    

    6、软键盘问题

    //默认软键盘不弹出
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    //软键盘把布局顶上去
    ``第一:最外层用ScrollView,子布局只能一个
    第二:ScrollView去掉nobar属性
    第三:去掉配置文件的android:configChanges="keyboardHidden|orientation|screenSize"```
    
    

    相关文章

      网友评论

        本文标题:安卓之项目实战经验总结(2)

        本文链接:https://www.haomeiwen.com/subject/hylqyttx.html