LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.setMargins(left, top, right, bottom); imageView.setLayoutParams(lp);
LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(30, 20, 30, 0); Button okButton=new Button(this); okButton.setText("some text"); ll.addView(okButton, layoutParams);
layout = (LinearLayout) findViewById(R.id.layoutbtnlinear_aboutme); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)layout.getLayoutParams(); params.setMargins(0, 50, 0, 0); layout.setLayoutParams(params);
@Override public void onBindViewHolder(ProductViewHolder holder, int position) { Product product = products.get(position); holder.cover.setImageResource(product.coverResId); holder.title.setText(product.title); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT); int margin_horizontal = context.getResources().getDimensionPixelSize(R.dimen.padding_size_default); if(position % 2 == 0) { lp.setMargins(margin_horizontal, margin_horizontal/2, margin_horizontal/2, margin_horizontal/2); } else { lp.setMargins(margin_horizontal/2, margin_horizontal/2, margin_horizontal, margin_horizontal/2); } holder.itemView.setLayoutParams(lp); }
AlertDialog.Builder myDialog = new AlertDialog.Builder(Login.this); Button button = new Button(Login.this); EditText editText = new EditText(Login.this); TextView textView = new TextView(Login.this); button.setText("Send"); LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); buttonLayoutParams.setMargins(50, 10, 0, 0); button.setLayoutParams(buttonLayoutParams); String resetPassword = editText.getText().toString(); LinearLayout layout = new LinearLayout(Login.this); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(textView); layout.addView(editText); layout.addView(button); myDialog.setView(layout); myDialog.show();
@Override public void onBindViewHolder(ProductViewHolder holder, int position) { Product product = products.get(position); holder.cover.setImageResource(product.coverResId); holder.title.setText(product.title); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); int margin_horizontal = context.getResources().getDimensionPixelSize(R.dimen.padding_size_default); if(position % 2 == 0) { lp.setMargins(margin_horizontal, margin_horizontal/2, margin_horizontal/2, margin_horizontal/2); } else { lp.setMargins(margin_horizontal/2, margin_horizontal/2, margin_horizontal, margin_horizontal/2); } holder.itemView.setLayoutParams(lp); }
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.setMargins(0, 2, 0, 0); button.setLayoutParams(params);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); params.setMargins(10,10,10,10); tv1.setLayoutParams(params);
TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs); final int tabChildrenCount = tabWidget.getChildCount(); View currentView; for (int i = 0; i < tabChildrenCount; i++) { currentView = tabWidget.getChildAt(i); LinearLayout.LayoutParams currentLayout = (LinearLayout.LayoutParams) currentView.getLayoutParams(); currentLayout.setMargins(0, 5, 5, 0); } tabWidget.requestLayout();
private View getSeparatorView() { View separator = new View(activity); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); int m8 = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()); int m5 = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()); params.setMargins(m8, m5, m8, m5); separator.setLayoutParams(params); TypedValue typedValue = new TypedValue(); activity.getTheme().resolveAttribute(R.attr.separator_color, typedValue, true); separator.setBackgroundColor(typedValue.data); return separator; }
private void initLayoutParams() { mLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); mLayoutParams.setMargins(5, 5, 5, 5); mLayoutParams.width = 0; }
private void initImageLayoutParams() { int wrap = LayoutParams.WRAP_CONTENT; int match = LayoutParams.MATCH_PARENT; onePicPara = new LayoutParams(wrap, wrap); moreParaColumnFirst = new LayoutParams(pxMoreWandH, pxMoreWandH); morePara = new LayoutParams(pxMoreWandH, pxMoreWandH); morePara.setMargins(pxImagePadding, 0, 0, 0); rowPara = new LayoutParams(match, wrap); }
// NOT WORKING: LinearLayout.LayoutParams params = (LayoutParams) getLayoutParams(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); int tbm = AllConversationsActivity.topAndBottomMargin; int lrm = AllConversationsActivity.leftAndRightMargin; params.setMargins(tbm, lrm, tbm, lrm); setLayoutParams(params);
public void setCenterSpaceHeight(int centerSpaceHeight) { topTVParams.setMargins(0, 0, 0, centerSpaceHeight); centerTVParams.setMargins(0, 0, 0, 0); bottomTVParams.setMargins(0, centerSpaceHeight, 0, 0); }
private void initImageLayoutParams() { int wrap = LayoutParams.WRAP_CONTENT; int match = LayoutParams.MATCH_PARENT; //pxOneMaxWandH onePicPara = new LayoutParams(match, wrap); moreParaColumnFirst = new LayoutParams(pxMoreWandH, pxMoreWandH); morePara = new LayoutParams(pxMoreWandH, pxMoreWandH); morePara.setMargins(pxImagePadding, 0, 0, 0); rowPara = new LayoutParams(match, wrap); }
// CODE FOR ADD MARGINS LinearLayout.LayoutParams relativeParams = new LinearLayout.LayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); relativeParams.setMargins(0, 80, 0, 0); relativeLayout.setLayoutParams(relativeParams); relativeLayout.requestLayout();
LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(10, 20, 30, 40); Button button = new Button(this); button.setText("some text"); layout.addView(button, params);
public MultiItemRowListAdapter(Context context, ListAdapter adapter, int itemsPerRow, int cellSpacing) { if (itemsPerRow <= 0) { throw new IllegalArgumentException("Number of items per row must be positive"); } mContextReference = new WeakReference<Context>(context); mAdapter = adapter; mItemsPerRow = itemsPerRow; mCellSpacing = cellSpacing; mItemLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT); mItemLayoutParams.setMargins(cellSpacing, cellSpacing, 0, 0); mItemLayoutParams.weight = 1; mRowLayoutParams = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); }
TextView forgot_pswrd = (TextView) findViewById(R.id.ForgotPasswordText); forgot_pswrd.setOnTouchListener(this); LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); llp.setMargins(50, 0, 0, 0); // llp.setMargins(left, top, right, bottom); forgot_pswrd.setLayoutParams(llp);
TextView tv = (TextView)findViewById(R.id.my_text_view); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)tv.getLayoutParams(); params.setMargins(0, 0, 10, 0); //substitute parameters for left, top, right, bottom tv.setLayoutParams(params);