move View Vertical - Android User Interface

Android examples for User Interface:View Slide

Description

move View Vertical

Demo Code


//package com.java2s;

import android.view.View;

import android.view.ViewGroup.MarginLayoutParams;

public class Main {
    public static void moveVertical(final View v, final float distance) {
        final MarginLayoutParams lp = (MarginLayoutParams) v
                .getLayoutParams();/*from   w w w  .j  a v  a  2  s .  com*/
        final int newTopMargin = (int) (lp.topMargin + distance);
        setMarginTop(v, newTopMargin);
    }

    public static void setMarginTop(final View v, final int margin) {
        final MarginLayoutParams lp = (MarginLayoutParams) v
                .getLayoutParams();
        lp.setMargins(lp.leftMargin, margin, lp.rightMargin,
                lp.bottomMargin);
        v.setLayoutParams(lp);
    }
}

Related Tutorials