本文整理汇总了Java中android.widget.RelativeLayout.setId方法的典型用法代码示例。如果您正苦于以下问题:Java RelativeLayout.setId方法的具体用法?Java RelativeLayout.setId怎么用?Java RelativeLayout.setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.RelativeLayout
的用法示例。
在下文中一共展示了RelativeLayout.setId方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import android.widget.RelativeLayout; //导入方法依赖的package包/类
private void init() {
setOrientation(LinearLayout.VERTICAL);
nodeContainer = new RelativeLayout(getContext());
nodeContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
nodeContainer.setId(R.id.node_header);
ContextThemeWrapper newContext = new ContextThemeWrapper(getContext(), containerStyle);
nodeItemsContainer = new LinearLayout(newContext, null, containerStyle);
nodeItemsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
nodeItemsContainer.setId(R.id.node_items);
nodeItemsContainer.setOrientation(LinearLayout.VERTICAL);
nodeItemsContainer.setVisibility(View.GONE);
addView(nodeContainer);
addView(nodeItemsContainer);
}
示例2: init
import android.widget.RelativeLayout; //导入方法依赖的package包/类
private void init(){
cal = Calendar.getInstance();
base = new RelativeLayout(context);
base.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
base.setMinimumHeight(50);
base.setId(4);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.leftMargin = 16;
params.topMargin = 50;
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
prev = new ImageView(context);
prev.setId(1);
prev.setLayoutParams(params);
prev.setImageResource(R.drawable.navigation_previous_item);
prev.setOnClickListener(this);
base.addView(prev);
params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
params.addRule(RelativeLayout.CENTER_VERTICAL);
month = new TextView(context);
month.setId(2);
month.setLayoutParams(params);
month.setTextAppearance(context, android.R.attr.textAppearanceLarge);
month.setText(cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())+" "+cal.get(Calendar.YEAR));
month.setTextSize(25);
base.addView(month);
params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.rightMargin = 16;
params.topMargin = 50;
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
next = new ImageView(context);
next.setImageResource(R.drawable.navigation_next_item);
next.setLayoutParams(params);
next.setId(3);
next.setOnClickListener(this);
base.addView(next);
addView(base);
params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.bottomMargin = 20;
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.BELOW, base.getId());
calendar = new GridView(context);
calendar.setLayoutParams(params);
calendar.setVerticalSpacing(4);
calendar.setHorizontalSpacing(4);
calendar.setNumColumns(7);
calendar.setChoiceMode(GridView.CHOICE_MODE_SINGLE);
calendar.setDrawSelectorOnTop(true);
calendar.setFocusable(false);
mAdapter = new CalendarAdapter(context,cal);
calendar.setAdapter(mAdapter);
calendar.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return calendarGesture.onTouchEvent(event);
}
});
addView(calendar);
}
示例3: initGlobalViews
import android.widget.RelativeLayout; //导入方法依赖的package包/类
/**
* 初始化全局视图
*
* @param context
*/
private void initGlobalViews(Context context) {
ViewGroup.LayoutParams globalParams = new ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT);
setLayoutParams(globalParams);
// 构建标题栏填充视图
boolean supprotStatusBarLightMode = false;
try {
supprotStatusBarLightMode = TitleCompatibilityUtil.supportStatusBarLightMode(getContext());
} catch (ClassCastException e) {
e.printStackTrace();
}
if (fillStatusBar && supprotStatusBarLightMode) {
int statusBarHeight = TitleCompatibilityUtil.getStatusBarHeight();
viewStatusBarFill = new View(context);
viewStatusBarFill.setId(ViewFinder.generateViewId());
viewStatusBarFill.setBackgroundColor(statusBarColor);
LayoutParams statusBarParams = new LayoutParams(MATCH_PARENT, statusBarHeight);
statusBarParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
addView(viewStatusBarFill, statusBarParams);
}
// 构建主视图
rlMain = new RelativeLayout(context);
rlMain.setId(ViewFinder.generateViewId());
rlMain.setBackgroundColor(titleBarColor);
LayoutParams mainParams = new LayoutParams(MATCH_PARENT, titleBarHeight);
if (fillStatusBar) {
if (viewStatusBarFill != null)
mainParams.addRule(RelativeLayout.BELOW, viewStatusBarFill.getId());
} else {
mainParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
}
// 计算主布局高度
if (showBottomLine) {
mainParams.height = titleBarHeight - Math.max(1, ScreenUtils.dp2PxInt(0.4f));
} else {
mainParams.height = titleBarHeight;
}
addView(rlMain, mainParams);
// 构建分割线视图
if (showBottomLine) {
// 已设置显示标题栏分隔线,5.0以下机型,显示分隔线
viewBottomLine = new View(context);
viewBottomLine.setBackgroundColor(bottomLineColor);
LayoutParams bottomLineParams = new LayoutParams(MATCH_PARENT, Math.max(1, ScreenUtils.dp2PxInt(0.4f)));
bottomLineParams.leftMargin = ScreenUtils.dp2PxInt(15f);
bottomLineParams.rightMargin = ScreenUtils.dp2PxInt(15f);
bottomLineParams.addRule(RelativeLayout.BELOW, rlMain.getId());
addView(viewBottomLine, bottomLineParams);
mFadeViewList.add(viewBottomLine);
}
}
示例4: loadNotifications
import android.widget.RelativeLayout; //导入方法依赖的package包/类
private void loadNotifications() {
JSONObject jsonObj = app.notifications;
Iterator<String> keys = jsonObj.keys();
LinearLayout linear = (LinearLayout)getActivity().findViewById(R.id.fragments_view);
if (linear == null)
return; //Fix error caused by a bad refresh cycle that deletes the linearlayout
linear.removeAllViewsInLayout(); //Clear before any use
int i = 1;
while( keys.hasNext() ){
String key = keys.next(); // Get key in json object
if (!key.equals("count")) {
//Set Extra
NotificationListFragment intent = new NotificationListFragment();
Bundle b = new Bundle();
b.putString(Common.HOME_EXTRA_TYPE, key);
intent.setArguments(b);
//Create View and add it
RelativeLayout fragment = new RelativeLayout(getActivity());
fragment.setId(i);
getFragmentManager().beginTransaction().add(fragment.getId(), intent, null).commitAllowingStateLoss(); //commitAllowingStateLoss insteaf of commit to fix a bug Exception java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
linear.addView(fragment);
i++;
}
}
if (i<2) { //1 or 0 Means really 0
notiLLayout.setVisibility(View.GONE);
} else {
notiLLayout.setVisibility(View.VISIBLE);
}
}
示例5: create
import android.widget.RelativeLayout; //导入方法依赖的package包/类
public static RelativeLayout create(Context context) {
SizeHelper.prepare(context);
RelativeLayout root = new RelativeLayout(context);
root.setId(ResHelper.getIdRes(context, "rl_lv_item_bg"));
AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
SizeHelper.fromPxWidth(95));
root.setLayoutParams(params);
int padding = SizeHelper.fromPxWidth(14);
root.setPadding(padding, padding, padding, padding);
root.setGravity(Gravity.CENTER_VERTICAL);
root.setBackgroundColor(0xffffffff);
AsyncImageView contactImage = new AsyncImageView(context);
contactImage.setId(ResHelper.getIdRes(context, "iv_contact"));
RelativeLayout.LayoutParams contactImageParams = new RelativeLayout.LayoutParams(SizeHelper.fromPxWidth(64),
SizeHelper.fromPxWidth(64));
contactImageParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
contactImage.setLayoutParams(contactImageParams);
contactImage.setScaleType(ScaleType.FIT_CENTER);
root.addView(contactImage);
LinearLayout wrapper = new LinearLayout(context);
RelativeLayout.LayoutParams wrapperParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
wrapperParams.addRule(RelativeLayout.RIGHT_OF, ResHelper.getIdRes(context, "iv_contact"));
wrapperParams.addRule(RelativeLayout.CENTER_VERTICAL);
wrapperParams.leftMargin = SizeHelper.fromPxWidth(12);
wrapper.setLayoutParams(wrapperParams);
wrapper.setOrientation(LinearLayout.VERTICAL);
root.addView(wrapper);
TextView name = new TextView(context);
name.setId(ResHelper.getIdRes(context, "tv_name"));
LinearLayout.LayoutParams nameParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
name.setLayoutParams(nameParams);
name.setTextColor(0xff333333);
name.setTextSize(TypedValue.COMPLEX_UNIT_PX,SizeHelper.fromPxWidth(28));
wrapper.addView(name);
TextView contact = new TextView(context);
contact.setId(ResHelper.getIdRes(context, "tv_contact"));
LinearLayout.LayoutParams contactParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
contact.setLayoutParams(contactParams);
contact.setTextColor(0xff999999);
contact.setTextSize(TypedValue.COMPLEX_UNIT_PX,SizeHelper.fromPxWidth(22));
wrapper.addView(contact);
Button add = new Button(context);
add.setId(ResHelper.getIdRes(context, "btn_add"));
RelativeLayout.LayoutParams addParams = new RelativeLayout.LayoutParams(SizeHelper.fromPxWidth(92),
SizeHelper.fromPxWidth(46));
addParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
addParams.addRule(RelativeLayout.CENTER_VERTICAL);
add.setLayoutParams(addParams);
int resid = ResHelper.getStringRes(context, "smssdk_add_contact");
add.setText(resid);
add.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(22));
add.setTextColor(0xff797979);
//resid = R.getBitmapRes(context, "smssdk_corners_bg");
add.setBackgroundDrawable(DrawableHelper.createCornerBg(context));
add.setPadding(0, 0, 0, 0);
root.addView(add);
return root;
}
示例6: BaseMessageDialog
import android.widget.RelativeLayout; //导入方法依赖的package包/类
protected BaseMessageDialog(Activity activity, boolean fullscreen, BaseMessageOptions options,
WebInterstitialOptions webOptions, HTMLOptions htmlOptions) {
super(activity, getTheme(activity));
SizeUtil.init(activity);
this.activity = activity;
this.options = options;
this.webOptions = webOptions;
this.htmlOptions = htmlOptions;
if (webOptions != null) {
isWeb = true;
}
if (htmlOptions != null) {
isHtml = true;
}
dialogView = new RelativeLayout(activity);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
dialogView.setBackgroundColor(Color.TRANSPARENT);
dialogView.setLayoutParams(layoutParams);
RelativeLayout view = createContainerView(activity, fullscreen);
view.setId(108);
dialogView.addView(view, view.getLayoutParams());
if ((!isWeb || (webOptions != null && webOptions.hasDismissButton())) && !isHtml) {
CloseButton closeButton = createCloseButton(activity, fullscreen, view);
dialogView.addView(closeButton, closeButton.getLayoutParams());
}
setContentView(dialogView, dialogView.getLayoutParams());
dialogView.setAnimation(createFadeInAnimation());
if (!fullscreen) {
Window window = getWindow();
if (window == null) {
return;
}
if (!isHtml) {
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
if (Build.VERSION.SDK_INT >= 14) {
window.setDimAmount(0.7f);
}
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
if (htmlOptions != null &&
MessageTemplates.Args.HTML_ALIGN_BOTTOM.equals(htmlOptions.getHtmlAlign())) {
dialogView.setGravity(Gravity.BOTTOM);
}
}
}
}