scale View From Layout Parameter and Pixel - Android User Interface

Android examples for User Interface:Layout

Description

scale View From Layout Parameter and Pixel

Demo Code


//package com.java2s;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout.LayoutParams;

public class Main {
    public static LayoutParams scaleFrom(View v, LayoutParams params,
            int pixel) {
        Log.d("pixel", "onScroll: " + pixel);
        params = cloneParams(params);//from  ww w  . j a v  a  2  s .  c  o m
        params.leftMargin -= pixel;
        params.rightMargin -= pixel;
        params.topMargin -= pixel;
        params.bottomMargin -= pixel;
        Log.d("pixel", "onScroll: " + pixel);
        v.setLayoutParams(params);

        return params;
    }

    public static LayoutParams cloneParams(LayoutParams params) {
        LayoutParams copy = new LayoutParams(params.width, params.height);
        copy.leftMargin = params.leftMargin;
        copy.topMargin = params.topMargin;
        copy.rightMargin = params.rightMargin;
        copy.bottomMargin = params.bottomMargin;
        int[] rules = params.getRules();
        for (int i = 0; i < rules.length; i++) {
            copy.addRule(i, rules[i]);
        }
        copy.setMarginStart(params.getMarginStart());
        copy.setMarginEnd(params.getMarginEnd());

        return copy;
    }
}

Related Tutorials