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);
LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL);
LinearLayout myRoot = (LinearLayout) findViewById(R.id.my_root); LinearLayout a = new LinearLayout(this); a.setOrientation(LinearLayout.HORIZONTAL); a.addView(view1); a.addView(view2); a.addView(view3); myRoot.addView(a);
@Override @NonNull protected LinearLayout makeCenterView() { LinearLayout rootLayout = new LinearLayout(activity); rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); rootLayout.setOrientation(LinearLayout.VERTICAL); rootLayout.setBackgroundColor(Color.WHITE); ListView listView = new ListView(activity); listView.setBackgroundColor(Color.WHITE); listView.setDivider(new ColorDrawable(0xFFDDDDDD)); listView.setDividerHeight(1); listView.setCacheColorHint(Color.TRANSPARENT); listView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT)); listView.setAdapter(adapter); listView.setOnItemClickListener(this); rootLayout.addView(listView); emptyView = new TextView(activity); LinearLayout.LayoutParams txtParams = new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT); txtParams.gravity = Gravity.CENTER; emptyView.setLayoutParams(txtParams); emptyView.setGravity(Gravity.CENTER); emptyView.setVisibility(View.GONE); emptyView.setTextColor(Color.BLACK); rootLayout.addView(emptyView); return rootLayout; }
private void useScaledImage() { Resources res = getResources(); BitmapDrawable bd = (BitmapDrawable)res.getDrawable(R.drawable.sun); Bitmap b = Bitmap.createScaledBitmap(bd.getBitmap(), (int) (bd.getIntrinsicHeight() * 0.7), (int) (bd.getIntrinsicWidth() * 0.7), false); LinearLayout l = new LinearLayout(this); ImageView iv = new ImageView(this); iv.setImageDrawable(new BitmapDrawable(b)); iv.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); l.addView(iv); setContentView(l); }
mArrowView = new ImageView(context); mProgressView = new ImageView(context); mTitleText = new TextView(context); mTitleText.setTextColor(0xff666666); mCenterLayout = new LinearLayout(context); mCenterLayout.setGravity(Gravity.CENTER_HORIZONTAL); mCenterLayout.setOrientation(LinearLayout.VERTICAL);
private void ensureFooterViewContainer() { if (mFooterViewContainer == null) { mFooterViewContainer = new LinearLayout(getContext()); mFooterViewContainer.setOrientation(LinearLayout.VERTICAL); mFooterViewContainer.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } }
public class ServiceWithWebView extends Service { @Override public void onCreate() { super.onCreate(); WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT); params.gravity = Gravity.TOP | Gravity.LEFT; params.x = 0; params.y = 0; params.width = 0; params.height = 0; LinearLayout view = new LinearLayout(this); view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); WebView wv = new WebView(this); wv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); view.addView(wv); wv.loadUrl("http://google.com"); windowManager.addView(view, params); } }
/** * method execute order: * show:constrouctor---show---oncreate---onStart---onAttachToWindow * dismiss:dismiss---onDetachedFromWindow---onStop * * @param context */ public BaseAlertDialog(Context context) { super(context); widthScale(0.88f); mLlContainer = new LinearLayout(context); mLlContainer.setOrientation(LinearLayout.VERTICAL); /** title */ mTvTitle = new TextView(context); /** content */ mTvContent = new TextView(context); /**btns*/ mLlBtns = new LinearLayout(context); mLlBtns.setOrientation(LinearLayout.HORIZONTAL); mTvBtnLeft = new TextView(context); mTvBtnLeft.setGravity(Gravity.CENTER); mTvBtnMiddle = new TextView(context); mTvBtnMiddle.setGravity(Gravity.CENTER); mTvBtnRight = new TextView(context); mTvBtnRight.setGravity(Gravity.CENTER); }
LinearLayout ll = new LinearLayout(this); Button b = new Button(this); b.setText("hello world"); ll.addView(b); ll.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); this.addContentView(ll, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
//LinearLayOut Setup LinearLayout linearLayout= new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); //ImageView Setup ImageView imageView = new ImageView(this); //setting image resource imageView.setImageResource(R.drawable.play); //setting image position imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); //adding view to layout linearLayout.addView(imageView); //make visible to program setContentView(linearLayout);
LinearLayout lila1= new LinearLayout(this); lila1.setOrientation(LinearLayout.VERTICAL); final EditText input = new EditText(this); final EditText input1 = new EditText(this); lila1.addView(input); lila1.addView(input1); alert.setView(lila1);
@Override public View getView(int position, View convertView, ViewGroup parent) { LinearLayout linearLayout = new LinearLayout(ApplicationProvider.getApplicationContext()); linearLayout.addView(new View(ApplicationProvider.getApplicationContext())); return linearLayout; } }
private void ensureHeaderViewContainer() { if (mHeaderViewContainer == null) { mHeaderViewContainer = new LinearLayout(getContext()); mHeaderViewContainer.setOrientation(LinearLayout.VERTICAL); mHeaderViewContainer.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } }
private void initialize(Context context) { edgePadding = getResources().getDimensionPixelSize(R.dimen.com_facebook_likeview_edge_padding); internalPadding = getResources().getDimensionPixelSize(R.dimen.com_facebook_likeview_internal_padding); if (foregroundColor == NO_FOREGROUND_COLOR) { foregroundColor = getResources().getColor(R.color.com_facebook_likeview_text_color); } setBackgroundColor(Color.TRANSPARENT); containerView = new LinearLayout(context); LayoutParams containerViewLayoutParams = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); containerView.setLayoutParams(containerViewLayoutParams); initializeLikeButton(context); initializeSocialSentenceView(context); initializeLikeCountView(context); containerView.addView(likeButton); containerView.addView(socialSentenceView); containerView.addView(likeBoxCountView); addView(containerView); setObjectIdAndTypeForced(this.objectId, this.objectType); updateLikeStateAndLayout(); }
LinearLayout lp=new LinearLayout(this); lp.addView(new Button(this)); lp.addView(new ImageButton(this)); //Now remove them lp.removeViewAt(0); // and so on
LinearLayout myLayout = new LinearLayout(this); myLayout.setOrientation(LinearLayout.VERTICAL);
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);
alertDialog.setTitle("Values"); final EditText quantity = new EditText(SecondScan.this); final EditText lot = new EditText(SecondScan.this); quantity.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); lot.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); Project=arr[0].toString(); Item=arr[1].toString(); LinearLayout ll=new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(quantity); ll.addView(lot); alertDialog.setView(ll); alertDialog.setCancelable(false); alertDialog.setPositiveButton("Update", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //ACTION } }); AlertDialog alert = alertDialog.create(); alert.show();
@Test public void testHasNullLayoutParamsUntilAddedToParent() throws Exception { assertThat(view.getLayoutParams()).isNull(); new LinearLayout(context).addView(view); assertThat(view.getLayoutParams()).isNotNull(); }