本文整理匯總了Java中android.widget.RelativeLayout.setBackground方法的典型用法代碼示例。如果您正苦於以下問題:Java RelativeLayout.setBackground方法的具體用法?Java RelativeLayout.setBackground怎麽用?Java RelativeLayout.setBackground使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.RelativeLayout
的用法示例。
在下文中一共展示了RelativeLayout.setBackground方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: showBadgeAtIndex
import android.widget.RelativeLayout; //導入方法依賴的package包/類
/**
* Show badge at index
*
* @param itemIndex index
* @param badgeText badge count text
*/
public void showBadgeAtIndex(int itemIndex, int badgeText, @ColorInt int badgeColor) {
if (itemIndex < 0 || itemIndex > spaceItems.size()) {
throwArrayIndexOutOfBoundsException(itemIndex);
} else {
RelativeLayout badgeView = badgeList.get(itemIndex);
/**
* Set circle background to badge view
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
badgeView.setBackground(BadgeHelper.makeShapeDrawable(badgeColor));
} else {
badgeView.setBackgroundDrawable(BadgeHelper.makeShapeDrawable(badgeColor));
}
BadgeItem badgeItem = new BadgeItem(itemIndex, badgeText, badgeColor);
BadgeHelper.showBadge(badgeView, badgeItem, shouldShowBadgeWithNinePlus);
badgeSaveInstanceHashMap.put(itemIndex, badgeItem);
}
}
示例2: forceShowBadge
import android.widget.RelativeLayout; //導入方法依賴的package包/類
/**
* Force show badge without animation
*
* @param view target budge
* @param badgeItem BadgeItem object
*/
static void forceShowBadge(RelativeLayout view, BadgeItem badgeItem, boolean shouldShowBadgeWithNinePlus) {
Utils.changeViewVisibilityVisible(view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(makeShapeDrawable(badgeItem.getBadgeColor()));
} else {
view.setBackgroundDrawable(makeShapeDrawable(badgeItem.getBadgeColor()));
}
TextView badgeTextView = (TextView) view.findViewById(R.id.badge_text_view);
if (shouldShowBadgeWithNinePlus)
badgeTextView.setText(badgeItem.getBadgeText());
else
badgeTextView.setText(badgeItem.getFullBadgeText());
}
示例3: getImageWrapper
import android.widget.RelativeLayout; //導入方法依賴的package包/類
public static RelativeLayout getImageWrapper(Context context, MenuObject menuItem, int menuItemSize,
View.OnClickListener onCLick, View.OnLongClickListener onLongClick,
boolean showDivider) {
RelativeLayout imageWrapper = new RelativeLayout(context);
LinearLayout.LayoutParams imageWrapperLayoutParams = new LinearLayout.LayoutParams(menuItemSize, menuItemSize);
imageWrapper.setLayoutParams(imageWrapperLayoutParams);
imageWrapper.setOnClickListener(onCLick);
imageWrapper.setOnLongClickListener(onLongClick);
imageWrapper.addView(Utils.getItemImageButton(context, menuItem));
if (showDivider) {
imageWrapper.addView(getDivider(context, menuItem));
}
if (menuItem.getBgColor() != 0) {
imageWrapper.setBackgroundColor(menuItem.getBgColor());
} else if (menuItem.getBgDrawable() != null) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
imageWrapper.setBackgroundDrawable(menuItem.getBgDrawable());
} else {
imageWrapper.setBackground(menuItem.getBgDrawable());
}
} else if (menuItem.getBgResource() != 0) {
imageWrapper.setBackgroundResource(menuItem.getBgResource());
} else {
imageWrapper.setBackgroundColor(context.getResources().getColor(R.color.menu_item_background));
}
return imageWrapper;
}
示例4: initView
import android.widget.RelativeLayout; //導入方法依賴的package包/類
private void initView(Context context) {
RelativeLayout pointContainerRl = new RelativeLayout(context);
if (Build.VERSION.SDK_INT >= 16) {
pointContainerRl.setBackground(mPointContainerBackgroundDrawable);
} else {
pointContainerRl.setBackgroundDrawable(mPointContainerBackgroundDrawable);
}
pointContainerRl.setPadding(mPointContainerLeftRightPadding, mPointTopBottomMargin, mPointContainerLeftRightPadding, mPointTopBottomMargin);
LayoutParams pointContainerLp = new LayoutParams(RMP, RWC);
// 處理圓點在頂部還是底部
if ((mPointGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP) {
pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
} else {
pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
}
addView(pointContainerRl, pointContainerLp);
LayoutParams indicatorLp = new LayoutParams(RWC, RWC);
indicatorLp.addRule(CENTER_VERTICAL);
if (mIsNumberIndicator) {
mNumberIndicatorTv = new TextView(context);
mNumberIndicatorTv.setId(R.id.banner_indicatorId);
mNumberIndicatorTv.setGravity(Gravity.CENTER_VERTICAL);
mNumberIndicatorTv.setSingleLine(true);
mNumberIndicatorTv.setEllipsize(TextUtils.TruncateAt.END);
mNumberIndicatorTv.setTextColor(mNumberIndicatorTextColor);
mNumberIndicatorTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNumberIndicatorTextSize);
mNumberIndicatorTv.setVisibility(View.INVISIBLE);
if (mNumberIndicatorBackground != null) {
if (Build.VERSION.SDK_INT >= 16) {
mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
} else {
mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);
}
}
pointContainerRl.addView(mNumberIndicatorTv, indicatorLp);
} else {
mPointRealContainerLl = new LinearLayout(context);
mPointRealContainerLl.setId(R.id.banner_indicatorId);
mPointRealContainerLl.setOrientation(LinearLayout.HORIZONTAL);
mPointRealContainerLl.setGravity(Gravity.CENTER_VERTICAL);
pointContainerRl.addView(mPointRealContainerLl, indicatorLp);
}
LayoutParams tipLp = new LayoutParams(RMP, RWC);
tipLp.addRule(CENTER_VERTICAL);
mTipTv = new TextView(context);
mTipTv.setGravity(Gravity.CENTER_VERTICAL);
mTipTv.setSingleLine(true);
mTipTv.setEllipsize(TextUtils.TruncateAt.END);
mTipTv.setTextColor(mTipTextColor);
mTipTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
pointContainerRl.addView(mTipTv, tipLp);
int horizontalGravity = mPointGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
// 處理圓點在左邊、右邊還是水平居中
if (horizontalGravity == Gravity.LEFT) {
indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
tipLp.addRule(RelativeLayout.RIGHT_OF, R.id.banner_indicatorId);
mTipTv.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
} else if (horizontalGravity == Gravity.RIGHT) {
indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
} else {
indicatorLp.addRule(RelativeLayout.CENTER_HORIZONTAL);
tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
}
showPlaceholder();
}
示例5: initView
import android.widget.RelativeLayout; //導入方法依賴的package包/類
private void initView(Context context) {
RelativeLayout pointContainerRl = new RelativeLayout(context);
if (Build.VERSION.SDK_INT >= 16) {
pointContainerRl.setBackground(mPointContainerBackgroundDrawable);
} else {
pointContainerRl.setBackgroundDrawable(mPointContainerBackgroundDrawable);
}
pointContainerRl.setPadding(mPointContainerLeftRightPadding, mPointTopBottomMargin, mPointContainerLeftRightPadding, mPointTopBottomMargin);
LayoutParams pointContainerLp = new LayoutParams(RMP, RWC);
// 處理圓點在頂部還是底部
if ((mPointGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP) {
pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
} else {
pointContainerLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
}
addView(pointContainerRl, pointContainerLp);
LayoutParams indicatorLp = new LayoutParams(RWC, RWC);
indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
if (mIsNumberIndicator) {
mNumberIndicatorTv = new TextView(context);
mNumberIndicatorTv.setId(R.id.banner_indicatorId);
mNumberIndicatorTv.setGravity(Gravity.CENTER_VERTICAL);
mNumberIndicatorTv.setSingleLine(true);
mNumberIndicatorTv.setEllipsize(TextUtils.TruncateAt.END);
mNumberIndicatorTv.setTextColor(mNumberIndicatorTextColor);
mNumberIndicatorTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNumberIndicatorTextSize);
mNumberIndicatorTv.setVisibility(View.INVISIBLE);
if (mNumberIndicatorBackground != null) {
if (Build.VERSION.SDK_INT >= 16) {
mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
} else {
mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);
}
}
pointContainerRl.addView(mNumberIndicatorTv, indicatorLp);
} else {
mPointRealContainerLl = new LinearLayout(context);
mPointRealContainerLl.setId(R.id.banner_indicatorId);
mPointRealContainerLl.setOrientation(LinearLayout.HORIZONTAL);
mPointRealContainerLl.setGravity(Gravity.CENTER_VERTICAL);
pointContainerRl.addView(mPointRealContainerLl, indicatorLp);
}
LayoutParams tipLp = new LayoutParams(RMP, RWC);
tipLp.addRule(CENTER_VERTICAL);
mTipTv = new TextView(context);
mTipTv.setGravity(Gravity.CENTER_VERTICAL);
mTipTv.setSingleLine(true);
mTipTv.setEllipsize(TextUtils.TruncateAt.END);
mTipTv.setTextColor(mTipTextColor);
mTipTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize);
pointContainerRl.addView(mTipTv, tipLp);
int horizontalGravity = mPointGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
// 處理圓點在左邊、右邊還是水平居中
if (horizontalGravity == Gravity.LEFT) {
indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
tipLp.addRule(RelativeLayout.RIGHT_OF, R.id.banner_indicatorId);
mTipTv.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
} else if (horizontalGravity == Gravity.RIGHT) {
indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
} else {
indicatorLp.addRule(RelativeLayout.CENTER_HORIZONTAL);
tipLp.addRule(RelativeLayout.LEFT_OF, R.id.banner_indicatorId);
}
showPlaceholder();
}