Indentation for Android and Margin

I am animating properties and want to know which is faster - update fields or indents. Both updates are updated by expanding Property<T, V>.

public static final Property<View, Integer> LINEAR_TOP_MARGIN_PROPERTY = new Property<View, Integer>(Integer.class, "") {
    @Override
    public Integer get(View view) {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
        return params.topMargin;
    }

    @Override
    public void set(View view, Integer value) {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
        params.topMargin = value;
        view.requestLayout();
    }
};

public static final Property<View, Integer> PADDING_BOTTOM_PROPERTY = new Property<View, Integer>(Integer.class, "") {
    @Override
    public Integer get(View view) {
        return view.getPaddingBottom();
    }

    @Override
    public void set(View object, Integer value) {
        object.setPadding(
                object.getPaddingLeft(),
                object.getPaddingTop(),
                object.getPaddingRight(),
                value
        );
    }
};

The gasket looks more flexible because it works in any layout without extensive casting and verification LayoutParams. However, not all views have the same complement behavior.

+4
source share

Source: https://habr.com/ru/post/1568379/


All Articles