get View Bottom Including Margin - Android User Interface

Android examples for User Interface:View Margin

Description

get View Bottom Including 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 getBottomIncludingMargin(View view) {
        return view.getBottom() + getBottomMargin(view);
    }//w w w.  j a  va  2s . c  o  m

    public static int getBottomMargin(View view) {
        if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
            return ((LinearLayout.LayoutParams) view.getLayoutParams()).bottomMargin;
        } else if (view.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
            return ((RelativeLayout.LayoutParams) view.getLayoutParams()).bottomMargin;
        } else if (view.getLayoutParams() instanceof FrameLayout.LayoutParams) {
            return ((FrameLayout.LayoutParams) view.getLayoutParams()).bottomMargin;
        }
        return 0;
    }
}

Related Tutorials