Android 自己开发中的一些小问题记录

来源:互联网 发布:数据恢复美团 编辑:程序博客网 时间:2024/06/06 23:55

一直持续更新。

1  画笔(Button画线)


   GradientDrawable drawable=new GradientDrawable();
    drawable.setShape(GradientDrawable.RECTANGLE);//画框
    drawable.setStroke(1,Color.BLACK);//线条的宽度,颜色

   btn_cz=(Button) findViewById(R.id.hbb_btn_chongzhi);
    btn_cz.setBackground(drawable);

2  解决scallview与viewpager冲突的问题
   
   viewpager.setOnTouchListener(new OnTouchListener(){

                 @Override
                    public boolean onTouch(View v,MotionEvent event){

                    viewpager.getParent().requestDisallowInterceptTouchEvent(true);
                                  
                    return false;

               }


            });

3 解决listview里面单个item有Button的冲突
        在根布局xml文件中加上
        android:descendantFocusability="blocksDescendants"  




4      SimpleDateFormat formatter = new SimpleDateFormat(
                "yyyyMMdd");
        Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
    
        String str = formatter.format(curDate);

 
5   上下跳的动画
      TranslateAnimation animation = new TranslateAnimation(0, 0, -5, 50);
        animation.setInterpolator(new OvershootInterpolator());
        animation.setDuration(550);
        animation.setRepeatCount(Animation.INFINITE);
        animation.setRepeatMode(Animation.REVERSE);
        jiqiren.startAnimation(animation);


6   listview 去掉下划线
       android:divider="@null"

7  去掉item点击黄色
 
                android:fadingEdge="none"
                android:fadingEdgeLength="0dp"
                android:listSelector="#00000000"
8  onTouch事件  点击变背景,松开变回去
    imageButton.setOnTouchListener(new OnTouchListener(){     
                        @Override    
                        public boolean onTouch(View v, MotionEvent event) {     
                                if(event.getAction() == MotionEvent.ACTION_DOWN){     
                                        //更改为按下时的背景图片     
                                        v.setBackgroundResource(R.drawable.pressed);     
                                }else if(event.getAction() == MotionEvent.ACTION_UP){     
                                        //改为抬起时的图片     
                                        v.setBackgroundResource(R.drawable.released);     
                                }     
                                return false;     
                        }     
                });  
 
9  默认控件获取焦点

         hqjd.setFocusable(true);
        hqjd.setFocusableInTouchMode(true);
        hqjd.requestFocus();


10 透明度
    android:background="#50000000"



11 TextView行距
            android:lineSpacingExtra="4dp"


12  饼状图 属性
      http://blog.csdn.net/qidingquan/article/details/51693371
      http://blog.csdn.net/zcmain/article/details/53611245

13 使APP字体不随系统字体大小变化  在BaseActivity里面 onCreat  onResume里面加上这两句
   DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
   displayMetrics.scaledDensity = displayMetrics.density;

14 替换TextView中某字段
       shortcut_newbank_name.setText(shortcut_newbank_name.getText().toString().replace("x", "X"));
        
15 正则表达式 判断银行卡是否符合
    shortcut_newbank_name.getText().toString().matches("[\u4E00-\u9FA5]{2,10}(?:·[\u4E00-\u9FA5]{2,10})*")       

16 Activity淡入淡出
    this.overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);

17 保留两位小数
       DecimalFormat dft = new DecimalFormat("######0.00");

18   如调用系统通话应用

            IntentcallIntent=newIntent(Intent.ACTION_CALL,Uri.parse("tel:12345678");
            startActivity(callIntent);

19 给TextView加删除线

    txt_general_assets.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); 


20 沉浸式状态栏
        BaseActivity 的OnCreat中加上 //透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //透明导航栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        xml文件中,顶部布局加上   android:fitsSystemWindows="true"     android:clipToPadding="true"



原创粉丝点击