Example usage for android.widget ImageView getTop

List of usage examples for android.widget ImageView getTop

Introduction

In this page you can find the example usage for android.widget ImageView getTop.

Prototype

@ViewDebug.CapturedViewProperty
public final int getTop() 

Source Link

Document

Top position of this view relative to its parent.

Usage

From source file:com.htc.dotdesign.ToolBoxService.java

private void setSelectedColor(ImageView button) {
    Drawable select = getResources().getDrawable(R.drawable.dot_design_select);
    select.setColorFilter(getResources().getColor(R.color.overlay_color), Mode.SRC_IN);

    ImageView selectedIcon = (ImageView) mPalette.findViewById(R.id.selected);
    selectedIcon.setBackground(select);//  w ww .  ja  va 2 s  . c  o  m

    Resources res = getResources();
    int id = button.getId();
    int buttonLeft = button.getLeft();
    int buttonTop = button.getTop();
    int m1 = res.getDimensionPixelSize(R.dimen.margin_l);
    int m2 = res.getDimensionPixelSize(R.dimen.margin_m);
    int colorSize = res.getDimensionPixelSize(R.dimen.hv01);
    if (id == R.id.btn_color_11 || id == R.id.btn_color_12 || id == R.id.btn_color_13
            || id == R.id.btn_color_14) {
        buttonTop = m2;
    } else if (id == R.id.btn_color_21 || id == R.id.btn_color_22 || id == R.id.btn_color_23
            || id == R.id.btn_color_24) {
        buttonTop = m2 + colorSize + m1;
    } else {
        buttonTop = m2 + 2 * colorSize + 2 * m1;
    }

    if (id == R.id.btn_color_11 || id == R.id.btn_color_21 || id == R.id.btn_color_31) {
        buttonLeft = m2;
    } else if (id == R.id.btn_color_12 || id == R.id.btn_color_22 || id == R.id.btn_color_32) {
        buttonLeft = 3 * m2 + colorSize;
    } else if (id == R.id.btn_color_13 || id == R.id.btn_color_23 || id == R.id.btn_color_33) {
        buttonLeft = 5 * m2 + 2 * colorSize;
    } else {
        buttonLeft = 7 * m2 + 3 * colorSize;
    }

    int widthDiff = res.getDimensionPixelSize(R.dimen.select_color_width) - colorSize;
    int heightDiff = res.getDimensionPixelSize(R.dimen.select_color_height) - colorSize;
    int marginLeft = buttonLeft - (widthDiff / 2);
    int marginTop = buttonTop - (heightDiff / 2);

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) selectedIcon.getLayoutParams();
    params.setMargins(marginLeft, marginTop, 0, 0);
    selectedIcon.setLayoutParams(params);
    selectedIcon.setVisibility(View.VISIBLE);
}