月笔记(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

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

给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);
            }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Tcp/IP通信也是不安全的,在传输的时候也可能出现漏洞 查看正在运行的进程 adb shell ps -A |g...
    远远飘着云阅读 4,612评论 0 0
  • 原文链接:www.jianshu.com 1、查看最上层成activity名字: adb shell dumps...
    SmileToLin阅读 880评论 0 1
  • 1、查看最上层成activity名字:adb shell dumpsys activity | findstr "...
    waiwaaa阅读 1,378评论 0 0
  • 原:https://www.jianshu.com/p/980fea2c9457 1、查看最上层成activity...
    柒黍阅读 1,636评论 0 0
  • Eclipse中快捷键的使用 A:新建 ctrl + n B:格式化 ctrl+shift+f C:导入包 c...
    海洋_5ad4阅读 613评论 0 0