get View Top Margin - Android User Interface

Android examples for User Interface:View Margin

Description

get View Top Margin

Demo Code


//package com.java2s;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class Main {
    public static int getTopMargin(View view) {
        if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
            return ((LinearLayout.LayoutParams) view.getLayoutParams()).topMargin;
        } else if (view.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
            return ((RelativeLayout.LayoutParams) view.getLayoutParams()).topMargin;
        } else if (view.getLayoutParams() instanceof FrameLayout.LayoutParams) {
            return ((FrameLayout.LayoutParams) view.getLayoutParams()).topMargin;
        }//from   w  ww. j av a 2 s . c  o m
        return 0;
    }
}

Related Tutorials