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();
}
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;
}
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;
}
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);
}
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;
}
Aggregations