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);
Context context = mapView.getContext(); LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); final EditText titleBox = new EditText(context); titleBox.setHint("Title"); layout.addView(titleBox); final EditText descriptionBox = new EditText(context); descriptionBox.setHint("Description"); layout.addView(descriptionBox); dialog.setView(layout);
//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);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout parent = (LinearLayout) inflater.inflate(R.layout.main, null); for (int i = 0; i < 3; i++) { View custom = inflater.inflate(R.layout.custom, null); TextView tv = (TextView) custom.findViewById(R.id.text); tv.setText("Custom View " + i); parent.addView(custom); } setContentView(parent);
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { @Override public View getInfoWindow(Marker arg0) { return null; } @Override public View getInfoContents(Marker marker) { LinearLayout info = new LinearLayout(mContext); info.setOrientation(LinearLayout.VERTICAL); TextView title = new TextView(mContext); title.setTextColor(Color.BLACK); title.setGravity(Gravity.CENTER); title.setTypeface(null, Typeface.BOLD); title.setText(marker.getTitle()); TextView snippet = new TextView(mContext); snippet.setTextColor(Color.GRAY); snippet.setText(marker.getSnippet()); info.addView(title); info.addView(snippet); return info; } });
@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); }
LinearLayout linearLayout = new LinearLayout(context); linearLayout.setLayoutParams(new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); linearLayout.setOrientation(LinearLayout.VERTICAL); // Create a stand-alone view View myView = LayoutInflater.from(context) .inflate(R.layout.ownRootView, null, false); linearLayout.addView(myView);
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); } }
public final class PlaceSlideFragment extends Fragment { int imageResourceId; public PlaceSlideFragment(int i) { imageResourceId = i; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView image = new ImageView(getActivity()); image.setImageResource(imageResourceId); LinearLayout layout = new LinearLayout(getActivity()); layout.setLayoutParams(new LayoutParams()); layout.setGravity(Gravity.CENTER); layout.addView(image); return layout; } }
LinearLayout linearLayout = new LinearLayout(this); linearLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setBackgroundColor(0xff99ccff); TextView textView1 = new TextView(this); textView1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); textView1.setText("programmatically created TextView1"); textView1.setBackgroundColor(0xff66ff66); // hex color 0xAARRGGBB textView1.setPadding(20, 20, 20, 20); // in pixels (left, top, right, bottom) linearLayout.addView(textView1); TextView textView2 = new TextView(this); LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); // (left, top, right, bottom) textView2.setLayoutParams(layoutParams); textView2.setText("programmatically created TextView2"); textView2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); textView2.setBackgroundColor(0xffffdbdb); // hex color 0xAARRGGBB linearLayout.addView(textView2);
mContent.setOrientation(LinearLayout.VERTICAL); setUpTitle(); setUpWebView(); Drawable icon = getContext().getResources().getDrawable(R.drawable.twitter_icon); mTitle = new TextView(getContext()); mTitle.setText("Website"); mTitle.setTextColor(Color.WHITE); mTitle.setTypeface(Typeface.DEFAULT_BOLD); mTitle.setCompoundDrawablePadding(MARGIN + PADDING); mTitle.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); mContent.addView(mTitle); mContent.addView(mWebView); String title = mWebView.getTitle(); if (title != null && title.length() > 0){ mTitle.setText(title); if(title.equals("Twitter")){
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);
@Override public View getView(int position, View convertView, ViewGroup parent) { LinearLayout linearLayout = new LinearLayout(ApplicationProvider.getApplicationContext()); linearLayout.addView(new View(ApplicationProvider.getApplicationContext())); return linearLayout; } }
newLL.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); newLL.setGravity(Gravity.LEFT); newLL.setOrientation(LinearLayout.HORIZONTAL); LL.setOrientation(LinearLayout.HORIZONTAL); LL.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM); LL.setLayoutParams(new ListView.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); LL.addView(views[i], params); LL.measure(0, 0); ll.addView(newLL); newLL.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); newLL.setOrientation(LinearLayout.HORIZONTAL); newLL.setGravity(Gravity.LEFT); params = new LinearLayout.LayoutParams(LL .getMeasuredWidth(), LL.getMeasuredHeight()); newLL.addView(LL, params); widthSoFar = LL.getMeasuredWidth(); } else { newLL.addView(LL); ll.addView(newLL);