月笔记(2017-08)

  • 执行jar包命令:
    java -jar jar路径
  • StringBuffer和StringBuilder的区别
    StringBuffer是线程同步的,而StringBuilder不是.所以StringBuilder执行速度更快.如果是在多线程中使用的话.就推荐使用StringBuffer.StackoverFlow
  • 动态添加View,控制View的Margin方法

LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(30, 20, 30, 0);//这行代码生效,这里要根据dp设置px,不然会有屏幕适配的问题

Button okButton=new Button(this);
okButton.setText("some text"); 
ll.addView(okButton, layoutParams);

  • adb 打印出设置的长和宽
    两种方法:

adb shell dumpsys window | grep cur= |tr -s " " | cut -d " " -f 4|cut -d "=" -f 2

adb shell wm density
adb shell hm density
  • 控制Button圆角

新建orange_corner_bg.xml



    
    

给button设置背景

android:background="@drawable/orange_corner_bg"
  • 监听CoordinatorLayout的滑动
 if (appBarLayout != null) {
            CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
            AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
            if (behavior != null) {
                behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
                    @Override
                    public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
                        return behaviorDrag;
                    }
                });
            }
        }
  • CoordinatorLayout缩放
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
            AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
            if (behavior != null) {
                behavior.onNestedFling(coordinatorLayout, appBarLayout, null, 0, -params.height, true);
            }

你可能感兴趣的:(月笔记(2017-08))