GB 移动小组

月笔记(2017-08)

2017-09-02  本文已影响12人  寒冬_腊月

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 shell dumpsys window | grep cur= |tr -s " " | cut -d " " -f 4|cut -d "=" -f 2

adb shell wm density
adb shell hm density

新建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"
 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.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);
            }

上一篇 下一篇

猜你喜欢

热点阅读