Search in sources :

Example 6 with MarginLayoutParams

use of android.view.ViewGroup.MarginLayoutParams in project androidquery by androidquery.

the class AbstractAQuery method margin.

/**
	 * Set the margin of a view. Notes all parameters are in DIP, not in pixel.
	 *
	 * @param leftDip the left dip
	 * @param topDip the top dip
	 * @param rightDip the right dip
	 * @param bottomDip the bottom dip
	 * @return self
	 */
public T margin(float leftDip, float topDip, float rightDip, float bottomDip) {
    if (view != null) {
        LayoutParams lp = view.getLayoutParams();
        if (lp instanceof MarginLayoutParams) {
            Context context = getContext();
            int left = AQUtility.dip2pixel(context, leftDip);
            int top = AQUtility.dip2pixel(context, topDip);
            int right = AQUtility.dip2pixel(context, rightDip);
            int bottom = AQUtility.dip2pixel(context, bottomDip);
            ((MarginLayoutParams) lp).setMargins(left, top, right, bottom);
            view.setLayoutParams(lp);
        }
    }
    return self();
}
Also used : Context(android.content.Context) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) LayoutParams(android.view.ViewGroup.LayoutParams) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) Paint(android.graphics.Paint)

Example 7 with MarginLayoutParams

use of android.view.ViewGroup.MarginLayoutParams in project platform_frameworks_base by android.

the class RenderSessionImpl method createViewInfo.

/**
     * Creates a {@link ViewInfo} for the view. The {@code ViewInfo} corresponding to the children
     * of the {@code view} are not created. Consequently, the children of {@code ViewInfo} is not
     * set.
     * @param offset an offset for the view bounds. Used only if view is part of the content frame.
     */
private ViewInfo createViewInfo(View view, int offset, boolean setExtendedInfo, boolean isContentFrame) {
    if (view == null) {
        return null;
    }
    ViewParent parent = view.getParent();
    ViewInfo result;
    if (isContentFrame) {
        // Account for parent scroll values when calculating the bounding box
        int scrollX = parent != null ? ((View) parent).getScrollX() : 0;
        int scrollY = parent != null ? ((View) parent).getScrollY() : 0;
        // The view is part of the layout added by the user. Hence,
        // the ViewCookie may be obtained only through the Context.
        result = new ViewInfo(view.getClass().getName(), getContext().getViewKey(view), -scrollX + view.getLeft(), -scrollY + view.getTop() + offset, -scrollX + view.getRight(), -scrollY + view.getBottom() + offset, view, view.getLayoutParams());
    } else {
        // We are part of the system decor.
        SystemViewInfo r = new SystemViewInfo(view.getClass().getName(), getViewKey(view), view.getLeft(), view.getTop(), view.getRight(), view.getBottom(), view, view.getLayoutParams());
        result = r;
        // 3. The overflow popup button.
        if (view instanceof ListMenuItemView) {
            // Mark 2.
            // All menus in the popup are of type ListMenuItemView.
            r.setViewType(ViewType.ACTION_BAR_OVERFLOW_MENU);
        } else {
            // Mark 3.
            ViewGroup.LayoutParams lp = view.getLayoutParams();
            if (lp instanceof ActionMenuView.LayoutParams && ((ActionMenuView.LayoutParams) lp).isOverflowButton) {
                r.setViewType(ViewType.ACTION_BAR_OVERFLOW);
            } else {
                // actionProviderClass.
                while (parent != mViewRoot && parent instanceof ViewGroup) {
                    if (parent instanceof ActionMenuView) {
                        r.setViewType(ViewType.ACTION_BAR_MENU);
                        break;
                    }
                    parent = parent.getParent();
                }
            }
        }
    }
    if (setExtendedInfo) {
        MarginLayoutParams marginParams = null;
        LayoutParams params = view.getLayoutParams();
        if (params instanceof MarginLayoutParams) {
            marginParams = (MarginLayoutParams) params;
        }
        result.setExtendedInfo(view.getBaseline(), marginParams != null ? marginParams.leftMargin : 0, marginParams != null ? marginParams.topMargin : 0, marginParams != null ? marginParams.rightMargin : 0, marginParams != null ? marginParams.bottomMargin : 0);
    }
    return result;
}
Also used : ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) LayoutParams(android.view.ViewGroup.LayoutParams) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) LayoutParams(android.view.ViewGroup.LayoutParams) ActionMenuView(android.widget.ActionMenuView) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) ViewInfo(com.android.ide.common.rendering.api.ViewInfo)

Example 8 with MarginLayoutParams

use of android.view.ViewGroup.MarginLayoutParams in project twoway-view by lucasr.

the class SpannableGridLayoutManager method generateLayoutParams.

@Override
public LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
    final LayoutParams spannableLp = new LayoutParams((MarginLayoutParams) lp);
    spannableLp.width = LayoutParams.MATCH_PARENT;
    spannableLp.height = LayoutParams.MATCH_PARENT;
    if (lp instanceof LayoutParams) {
        final LayoutParams other = (LayoutParams) lp;
        if (isVertical()) {
            spannableLp.colSpan = Math.max(1, Math.min(other.colSpan, getLaneCount()));
            spannableLp.rowSpan = Math.max(1, other.rowSpan);
        } else {
            spannableLp.colSpan = Math.max(1, other.colSpan);
            spannableLp.rowSpan = Math.max(1, Math.min(other.rowSpan, getLaneCount()));
        }
    }
    return spannableLp;
}
Also used : MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams)

Example 9 with MarginLayoutParams

use of android.view.ViewGroup.MarginLayoutParams in project twoway-view by lucasr.

the class TwoWayLayoutManager method layoutDecorated.

@Override
public void layoutDecorated(View child, int left, int top, int right, int bottom) {
    final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
    super.layoutDecorated(child, left + lp.leftMargin, top + lp.topMargin, right - lp.rightMargin, bottom - lp.bottomMargin);
}
Also used : MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams)

Example 10 with MarginLayoutParams

use of android.view.ViewGroup.MarginLayoutParams in project twoway-view by lucasr.

the class BaseLayoutManager method generateLayoutParams.

@Override
public LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
    final LayoutParams lanedLp = new LayoutParams((MarginLayoutParams) lp);
    if (isVertical()) {
        lanedLp.width = LayoutParams.MATCH_PARENT;
        lanedLp.height = lp.height;
    } else {
        lanedLp.width = lp.width;
        lanedLp.height = LayoutParams.MATCH_PARENT;
    }
    return lanedLp;
}
Also used : LayoutParams(android.support.v7.widget.RecyclerView.LayoutParams) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams)

Aggregations

MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)40 ViewGroup (android.view.ViewGroup)15 LayoutParams (android.view.ViewGroup.LayoutParams)10 SuppressLint (android.annotation.SuppressLint)8 Paint (android.graphics.Paint)6 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)6 Point (android.graphics.Point)5 ViewParent (android.view.ViewParent)5 ActionMenuView (android.widget.ActionMenuView)5 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)5 Context (android.content.Context)4 View (android.view.View)4 TextView (android.widget.TextView)4 TextPaint (android.text.TextPaint)3 IntentFilter (android.content.IntentFilter)2 RemoteException (android.os.RemoteException)2 RecyclerView (android.support.v7.widget.RecyclerView)2 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)2 MotionEvent (android.view.MotionEvent)2 ImageView (android.widget.ImageView)2