List of usage examples for android.widget LinearLayout addView
public void addView(View child)
Adds a child view.
From source file:com.appfirst.activities.details.AFServerDetail.java
/** * Display the CPU data along with the graph. *///from ww w . j a va2 s. c o m private void setCpuData() { LinearLayout cpuCores = (LinearLayout) findViewById(R.id.serverCpuContainer); AFBarView barView = new AFBarView(this, data.getCpu() / 100); barView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); cpuCores.addView(barView); }
From source file:com.appfirst.activities.details.AFServerDetail.java
/** * Display the memory data along with the graph. *///from ww w. j a v a 2s . c o m private void setMemoryData() { Double capMemory = Double.MAX_VALUE; if (mServer.getCapacity_mem() != 0) { capMemory = Double.parseDouble(String.format("%d", mServer.getCapacity_mem())); } Double percentage = data.getMemory() / capMemory; LinearLayout container = (LinearLayout) findViewById(R.id.serverMemoryContainer); AFBarView barView = new AFBarView(this, percentage); barView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); container.addView(barView); }
From source file:com.chuger.bithdayapp.view.auth.AuthDialog.java
private void setUpWebView(final int margin) { final LinearLayout webViewContainer = new LinearLayout(getContext()); mWebView = new WebView(getContext()); mWebView.setVerticalScrollBarEnabled(false); mWebView.setHorizontalScrollBarEnabled(false); mWebView.setWebViewClient(new AuthDialog.FbWebViewClient()); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl(mUrl);/* w w w .j a v a 2s . com*/ mWebView.setLayoutParams(FILL); mWebView.setVisibility(View.INVISIBLE); webViewContainer.setPadding(margin, margin, margin, margin); webViewContainer.addView(mWebView); mContent.addView(webViewContainer); }
From source file:com.appfirst.activities.details.AFServerDetail.java
/** * Display the Disk data along with the graph. *//*from w w w. java2s .c o m*/ private void setDiskData() { LinearLayout container = (LinearLayout) findViewById(R.id.serverDiskContainer); AFBarView barView = new AFBarView(this, data.getDisk_percent() / 100); barView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); container.addView(barView); }
From source file:com.fullmeadalchemist.mustwatch.ui.batch.form.BatchFormFragment.java
private void updateUiIngredientsTable() { if (viewModel.batch.ingredients != null) { // FIXME: this is not performant and looks ghetto. Timber.d("Found %s BatchIngredients for this Batch; adding them to the ingredientsList", viewModel.batch.ingredients.size()); LinearLayout ingredientsList = activity.findViewById(R.id.ingredients_list); ingredientsList.removeAllViews(); for (BatchIngredient ingredient : viewModel.batch.ingredients) { BatchIngredientView ingredientView = new BatchIngredientView(activity); ingredientView.setBatchIngredient(ingredient); ingredientsList.addView(ingredientView); }// w ww. j av a 2 s.c om } else { Timber.d("No Ingredients found for this Recipe."); } }
From source file:fm.krui.kruifm.ScheduleFragment.java
/** * Adds a show to the schedule.//w ww. ja va2 s . co m * @param title Title of show to display * @param description Description of show to display * @param startTime Start time of show in minutes from midnight * @param endTime End time of show in minutes from midnight * @param category Format of this show, required to correctly color the event. * * Valid settings for category include: * 1 - Regular Rotation * 2 - Music Speciality * 3 - Sports * 4 - News/Talk * 5 - Specials */ private void addShow(String title, String description, int startTime, int endTime, int category) { /* Build the LinearLayout to function as the container for this show. Since the size of the container is to represent the length of the show, its height must be proportional (1dp = 1 minute) to the length. Determine length by finding the difference between the start and end times. */ // Fix for corner case of shows ending at midnight. if (endTime == 0) { endTime = 1440; } int difference = endTime - startTime; /* Define the margins of this show. All shows must not overlap the displayed times, which are 50dp in width. Add 5 more (to the right and left) to see the schedule lines for clarity. Push the show down to align with the appropriate time marker using the top margin value set to the difference (in minutes) between midnight and the start of the show. */ Log.v(TAG, "Configuring " + title); //Log.v(TAG, "Start time: " + startTime + " End time: " + endTime); //Log.v(TAG, "Setting parameters for " + title); RelativeLayout.LayoutParams rrLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, dpToPixels(difference)); rrLayoutParams.leftMargin = dpToPixels(55); //Log.v(TAG, "Left margin: " + rrLayoutParams.leftMargin); rrLayoutParams.topMargin = dpToPixels(startTime); //Log.v(TAG, "Top margin: " + rrLayoutParams.topMargin); rrLayoutParams.rightMargin = dpToPixels(5); //Log.v(TAG, "Right margin: " + rrLayoutParams.rightMargin); /* Build LinearLayout and apply parameters */ LinearLayout eventLL = new LinearLayout(getActivity()); eventLL.setOrientation(LinearLayout.VERTICAL); eventLL.setPadding(dpToPixels(5), dpToPixels(2), dpToPixels(5), dpToPixels(5)); // Get background for this event eventLL.setBackgroundResource(getEventBackground(category)); /* Add title of event to LinearLayout */ TextView titleTV = new TextView(getActivity()); // Title of a show should be bolded titleTV.setText(title); titleTV.setTypeface(null, Typeface.BOLD); titleTV.setPadding(dpToPixels(5), 0, dpToPixels(5), 0); eventLL.addView(titleTV); /* Determine length of event to see if we have room to attach a description (if one was passed) */ int length = endTime - startTime; /* Attach a description with a size that depends on the event length (longer events can hold more description text). */ if (description != null) { TextView descriptionTV = new TextView(getActivity()); descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5)); descriptionTV.setText(description); // ~hour long shows can display 1 line of description if (difference >= 30 && difference <= 60) { descriptionTV.setMaxLines(1); } // 1:30 long shows can display 2 lines of description else if (difference >= 60 && difference <= 90) { descriptionTV.setMaxLines(2); } // 2:00 long shows can display 4 lines of description else if (difference >= 120) { descriptionTV.setMaxLines(4); } descriptionTV.setEllipsize(TextUtils.TruncateAt.END); descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5)); eventLL.addView(descriptionTV); } /* Add this view to the schedule UI */ RelativeLayout rl = (RelativeLayout) rootView.findViewById(R.id.schedule_container_relativelayout); rl.addView(eventLL, rrLayoutParams); }
From source file:com.blueoxfords.peacecorpstinder.activities.MainActivity.java
public void getLegalInfo(View v) { String photoId = v.getTag() + ""; ImageRestClient.get().getInfoFromImageId(photoId, new Callback<ImageService.ImageInfoWrapper>() { @Override/*from w w w . j a v a 2 s.c o m*/ public void success(ImageService.ImageInfoWrapper imageInfoWrapper, Response response) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.activity); ScrollView wrapper = new ScrollView(MainActivity.activity); LinearLayout infoLayout = new LinearLayout(MainActivity.activity); infoLayout.setOrientation(LinearLayout.VERTICAL); infoLayout.setPadding(35, 35, 35, 35); TextView imageOwner = new TextView(MainActivity.activity); imageOwner.setText(Html.fromHtml("<b>Image By: </b>" + imageInfoWrapper.photo.owner.username)); if (imageInfoWrapper.photo.owner.realname.length() > 0) { imageOwner.setText(imageOwner.getText() + " (" + imageInfoWrapper.photo.owner.realname + ")"); } infoLayout.addView(imageOwner); if (getLicenseUrl(Integer.parseInt(imageInfoWrapper.photo.license)).length() > 0) { TextView licenseLink = new TextView(MainActivity.activity); licenseLink.setText(Html .fromHtml("<a href=\"" + getLicenseUrl(Integer.parseInt(imageInfoWrapper.photo.license)) + "\"><b>Licensing</b></a>")); licenseLink.setMovementMethod(LinkMovementMethod.getInstance()); infoLayout.addView(licenseLink); } if (imageInfoWrapper.photo.urls.url.size() > 0) { TextView imageLink = new TextView(MainActivity.activity); imageLink.setText(Html.fromHtml("<a href=\"" + imageInfoWrapper.photo.urls.url.get(0)._content + "\"><b>Image Link</b></a>")); imageLink.setMovementMethod(LinkMovementMethod.getInstance()); infoLayout.addView(imageLink); } if (imageInfoWrapper.photo.title._content.length() > 0) { TextView photoTitle = new TextView(MainActivity.activity); photoTitle .setText(Html.fromHtml("<b>Image Title: </b>" + imageInfoWrapper.photo.title._content)); infoLayout.addView(photoTitle); } if (imageInfoWrapper.photo.description._content.length() > 0) { TextView description = new TextView(MainActivity.activity); description.setText(Html .fromHtml("<b>Image Description: </b>" + imageInfoWrapper.photo.description._content)); infoLayout.addView(description); } TextView contact = new TextView(MainActivity.activity); contact.setText( Html.fromHtml("<br><i>To remove this photo, please email pcorpsconnect@gmail.com</i>")); infoLayout.addView(contact); wrapper.addView(infoLayout); builder.setTitle("Photo Information"); builder.setPositiveButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); builder.setView(wrapper); builder.create().show(); } @Override public void failure(RetrofitError error) { Log.i("testing", "could not retrieve legal/attribution info"); } }); }
From source file:com.grarak.cardview.BaseCardView.java
public BaseCardView(Context context, AttributeSet attributeSet, int layout) { super(context, attributeSet); // Add a margin setMargin();//from w w w . j a v a 2 s .c o m // Make a rounded card setRadius(); // Set background color depending on the current theme setCardBackgroundColor(ContextCompat.getColor(context, Utils.DARKTHEME ? R.color.card_background_dark : R.color.card_background_light)); // This will enable the touch feedback of the card TypedArray ta = getContext().obtainStyledAttributes(new int[] { R.attr.selectableItemBackground }); Drawable d = ta.getDrawable(0); ta.recycle(); setForeground(d); // null parent avoid Layout Inflation without a Parent ViewGroup base_parent = (ViewGroup) findViewById(R.id.base_parent); // Add the base view View view = LayoutInflater.from(getContext()).inflate(R.layout.base_cardview, base_parent, false); addView(view); headerLayout = (LinearLayout) view.findViewById(R.id.header_layout); setUpHeader(); LinearLayout innerLayout = (LinearLayout) view.findViewById(R.id.inner_layout); customLayout = (LinearLayout) view.findViewById(R.id.custom_layout); // Inflate the innerlayout layoutView = LayoutInflater.from(getContext()).inflate(layout, null, false); // If sub class overwrites the default layout then don't try to get the TextView if (layout == DEFAULT_LAYOUT) { innerView = (TextView) layoutView.findViewById(R.id.inner_view); if (mTitle != null) innerView.setText(mTitle); } else setUpInnerLayout(layoutView); // Add innerlayout to base view innerLayout.addView(layoutView); if (Utils.isTV(getContext())) setFocus(); }
From source file:com.klisly.bookbox.widget.draglistview.BoardView.java
public DragItemRecyclerView addColumnList(final DragItemAdapter adapter, final View header, boolean hasFixedItemSize) { final DragItemRecyclerView recyclerView = new DragItemRecyclerView(getContext()); recyclerView.setMotionEventSplittingEnabled(false); recyclerView.setDragItem(mDragItem); recyclerView.setLayoutParams(//w w w.java2 s .c om new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setHasFixedSize(hasFixedItemSize); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setDragItemListener(new DragItemRecyclerView.DragItemListener() { @Override public void onDragStarted(int itemPosition, float x, float y) { mDragStartColumn = getColumnOfList(recyclerView); mDragStartRow = itemPosition; mCurrentRecyclerView = recyclerView; mDragItem.setOffset(((View) mCurrentRecyclerView.getParent()).getX(), mCurrentRecyclerView.getY()); if (mBoardListener != null) { mBoardListener.onItemDragStarted(mDragStartColumn, mDragStartRow); } invalidate(); } @Override public void onDragging(int itemPosition, float x, float y) { } @Override public void onDragEnded(int newItemPosition) { if (mBoardListener != null) { mBoardListener.onItemDragEnded(mDragStartColumn, mDragStartRow, getColumnOfList(recyclerView), newItemPosition); } } }); recyclerView.setAdapter(adapter); recyclerView.setDragEnabled(mDragEnabled); adapter.setDragStartedListener(new DragItemAdapter.DragStartCallback() { @Override public boolean startDrag(View itemView, long itemId) { return recyclerView.startDrag(itemView, itemId, getListTouchX(recyclerView), getListTouchY(recyclerView)); } @Override public boolean isDragging() { return recyclerView.isDragging(); } }); LinearLayout layout = new LinearLayout(getContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setLayoutParams(new LayoutParams(mColumnWidth, LayoutParams.MATCH_PARENT)); if (header != null) { layout.addView(header); mHeaders.put(mLists.size(), header); } layout.addView(recyclerView); mLists.add(recyclerView); mColumnLayout.addView(layout); return recyclerView; }
From source file:com.huyn.demogroup.relativetop.PagerSlidingTabStrip.java
private void addIconAndTextTab(int position, int resId, String title) { LinearLayout tab = new LinearLayout(getContext()); tab.setGravity(Gravity.CENTER);//from w ww.ja v a 2 s. co m TextView text = new TextView(getContext()); text.setText(title); text.setTextColor(Color.WHITE); text.setGravity(Gravity.CENTER); text.setSingleLine(); ImageView img = new ImageView(getContext()); img.setImageBitmap(iProvider.getBitmap(resId)); tab.addView(img); tab.addView(text); text.setPadding(10, 0, 0, 0); text.setTag("TEXT"); addTab(position, tab); }