下面列出了android.graphics.drawable.NinePatchDrawable#getPadding() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ForegroundRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundRelativeLayout,
defStyle, 0);
final Drawable d = a.getDrawable(R.styleable.ForegroundRelativeLayout_foreground);
if (d != null) {
setForeground(d);
}
a.recycle();
if (this.getBackground() instanceof NinePatchDrawable) {
final NinePatchDrawable npd = (NinePatchDrawable) this.getBackground();
rectPadding = new Rect();
if (npd.getPadding(rectPadding)) {
useBackgroundPadding = true;
}
}
}
public ForegroundLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLinearLayout,
defStyle, 0);
final Drawable d = a.getDrawable(R.styleable.ForegroundRelativeLayout_foreground);
if (d != null) {
setForeground(d);
}
a.recycle();
if (this.getBackground() instanceof NinePatchDrawable) {
final NinePatchDrawable npd = (NinePatchDrawable) this.getBackground();
rectPadding = new Rect();
if (npd.getPadding(rectPadding)) {
useBackgroundPadding = true;
}
}
}
private void updateNinePatchBounds(NinePatchDrawable ninePatch, int childLeft, int childTop, int childRight, int childBottom) {
if (ninePatch == null) {
return;
}
final Rect t = mTempRect;
ninePatch.getPadding(t);
ninePatch.setBounds(
childLeft - t.left, childTop - t.top,
childRight + t.right, childBottom + t.bottom);
}
public ForegroundImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLayout, defStyle, 0);
final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground);
foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false);
backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false);
// Apply foreground padding for ninepatches automatically
if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) {
final NinePatchDrawable npd = (NinePatchDrawable) getBackground();
if (npd != null && npd.getPadding(rectPadding)) {
foregroundPadding = true;
}
}
final Drawable b = getBackground();
if (backgroundAsForeground && b != null) {
setForeground(b);
} else if (d != null) {
setForeground(d);
}
a.recycle();
}
public ForegroundRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLayout, defStyle, 0);
final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground);
foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false);
backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false);
// Apply foreground padding for ninepatches automatically
if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) {
final NinePatchDrawable npd = (NinePatchDrawable) getBackground();
if (npd != null && npd.getPadding(rectPadding)) {
foregroundPadding = true;
}
}
final Drawable b = getBackground();
if (backgroundAsForeground && b != null) {
setForeground(b);
} else if (d != null) {
setForeground(d);
}
a.recycle();
}
public ForegroundTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLayout, defStyle, 0);
final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground);
foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false);
backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false);
// Apply foreground padding for ninepatches automatically
if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) {
final NinePatchDrawable npd = (NinePatchDrawable) getBackground();
if (npd != null && npd.getPadding(rectPadding)) {
foregroundPadding = true;
}
}
final Drawable b = getBackground();
if (backgroundAsForeground && b != null) {
setForeground(b);
} else if (d != null) {
setForeground(d);
}
a.recycle();
}
public ForegroundLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLayout, defStyle, 0);
final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground);
foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false);
backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false);
// Apply foreground padding for ninepatches automatically
if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) {
final NinePatchDrawable npd = (NinePatchDrawable) getBackground();
if (npd != null && npd.getPadding(rectPadding)) {
foregroundPadding = true;
}
}
final Drawable b = getBackground();
if (backgroundAsForeground && b != null) {
setForeground(b);
} else if (d != null) {
setForeground(d);
}
a.recycle();
}