LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(100, 100); iv.setLayoutParams(layoutParams);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30); yourImageView.setLayoutParams(layoutParams);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, 100); lp.weight = 1;
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(100, 100); touched_image_view.setLayoutParams(layoutParams);
setContentView(R.id.main); ImageView iv = (ImageView) findViewById(R.id.left); int width = 60; int height = 60; LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(width,height); iv.setLayoutParams(parms);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 50)); img.setLayoutParams(lp);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams((ViewGroup.MarginLayoutParams)(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)));
LinearLayout ll1, ll2, ll3; /* Find these LinearLayout by ID i.e ll1=(LinearLayout)findViewById(R.id.ll1); */ LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, 100); lp.weight = 1; ll1.setLayoutParams(lp); ll2.setLayoutParams(lp); ll3.setLayoutParams(lp);
// 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();
setContentView(R.id.main); Display display = getWindowManager().getDefaultDisplay(); ImageView iv = (LinearLayout) findViewById(R.id.left); int width = display.getWidth(); // ((display.getWidth()*20)/100) int height = display.getHeight();// ((display.getHeight()*30)/100) LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(width,height); iv.setLayoutParams(parms);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); params.setMargins(10,10,10,10); tv1.setLayoutParams(params);
//assuming your layout is in a LinearLayout as its root LinearLayout layout = (LinearLayout)findViewById(R.id.rootlayout); ImageView image = new ImageView(this); image.setImageResource(R.drawable.image); int newHeight = getWindowManager().getDefaultDisplay().getHeight() / 2; int orgWidth = image.getDrawable().getIntrinsicWidth(); int orgHeight = image.getDrawable().getIntrinsicHeight(); //double check my math, this should be right, though int newWidth = Math.floor((orgWidth * newHeight) / orgHeight); //Use RelativeLayout.LayoutParams if your parent is a RelativeLayout LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( newWidth, newHeight); image.setLayoutParams(params); image.setScaleType(ImageView.ScaleType.CENTER_CROP); layout.addView(image);
int actionBarHeight = a.getDimensionPixelSize(indexOfAttrTextSize, -1); a.recycle(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, actionBarHeight); params.gravity = Gravity.CENTER_VERTICAL; params.weight = 1;
LinearLayout.LayoutParams params_rb = new LinearLayout.LayoutParams( (int)(8*density), (int)(8*density));
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30); yourImageView.setLayoutParams(layoutParams);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30); myImageView.setLayoutParams(layoutParams);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(140, 398); layoutParams.setMargins(24, 0, 24, 0); layout.addView(button,layoutParams);
ProgressBar progressBar = new ProgressBar(teste.this, null, android.R.attr.progressBarStyleHorizontal); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(300, 10); progressBar.setLayoutParams(params ); LinearLayout test = new LinearLayout(getApplicationContext()); test.addView(progressBar); setContentView(test);
public void horizontalScrollGalleryLayout () { HorizontalScrollView sv = new HorizontalScrollView(this); LinearLayout llh = new LinearLayout(this); llh.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams layoutParamsTV = new LinearLayout.LayoutParams(40, 40); LinearLayout.LayoutParams layoutParamsLL = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); for (int i=0; i<20; i++) { LinearLayout llv = new LinearLayout(this); llv.setOrientation(LinearLayout.VERTICAL); TestView testView1 = new TestView(this, Color.rgb(i*12, 0, 0)); TestView testView2 = new TestView(this, true, Color.rgb(i*12, i*12, 0)); TestView testView3 = new TestView(this, true, Color.rgb(0, i*12, 0)); llv.addView(testView1, layoutParamsTV); llv.addView(testView2, layoutParamsTV); llv.addView(testView3, layoutParamsTV); llh.addView(llv, layoutParamsLL); } sv.addView(llh, layoutParamsLL); setContentView(sv); }
left_layout.setLayoutParams(parms_left_layout); LinearLayout.LayoutParams parms_legen_layout = new LinearLayout.LayoutParams( 20, 20); parms_legen_layout.setMargins(0, 0, 20, 0);