List of usage examples for android.widget LinearLayout addView
public void addView(View child)
Adds a child view.
From source file:com.rainmakerlabs.bleepsample.BleepService.java
public void imgShow(Bitmap bitmap, String strImgMsg) { MainActivity.adlib.put(strImgMsg, bitmap); Log.d("Portal", "Added an image. Size is now " + MainActivity.adlib.size()); Log.i("Portal", "Image added for key " + strImgMsg); if (MainActivity.myGallery == null) return;// w ww . j av a2s.c o m if (MainActivity.gal_size < MainActivity.adlib.size()) { //new image has been added and the layout is initialized LinearLayout superLL = (LinearLayout) MainActivity.myGallery.getParent().getParent(); if (MainActivity.gal_size < 1) { ImageView imgSplash = (ImageView) superLL.findViewById(R.id.imgSplash); imgSplash.setVisibility(View.INVISIBLE); } LinearLayout layout = new LinearLayout(getApplicationContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); layout.setGravity(Gravity.CENTER); ImageView imageview = new ImageView(getApplicationContext()); imageview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1000)); imageview.setScaleType(ImageView.ScaleType.CENTER_CROP); imageview.setImageBitmap(bitmap); //Add a button to go with it Button btnBuy = new Button(getApplicationContext()); LinearLayout.LayoutParams btnParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); btnParams.setMargins(-10, -10, -10, -10); btnBuy.setLayoutParams(btnParams); btnBuy.setText("Buy Now (" + strImgMsg + ")"); btnBuy.setBackgroundColor(MainActivity.getDominantColor(bitmap)); btnBuy.setTextColor(Color.WHITE); btnBuy.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { Intent newActivity = new Intent(getApplicationContext(), WebActivity.class); newActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); newActivity.putExtra("URL", "https://portal-battlehack.herokuapp.com/"); startActivity(newActivity); } }); layout.addView(imageview); layout.addView(btnBuy); MainActivity.myGallery.addView(layout); MainActivity.gal_size++; } }
From source file:com.flipzu.flipzu.Recorder.java
@Override public void onCommentsReceived(Hashtable<String, String>[] comments) { debug.logV(TAG, "onCommentsReceived"); final LinearLayout cc = (LinearLayout) findViewById(R.id.comments_container); /* cleanup comments first */ cc.removeAllViews();//from w w w . j a v a 2 s.co m /* get pixel values for various DIPs */ final float scale = getResources().getDisplayMetrics().density; // final int pixel_10 = 10 / (int) (scale + 0.5f); final int pixel_5 = 5 / (int) (scale + 0.5f); // final int pixel_30 = 30 / (int) (scale + 0.5f); final LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); if (comments != null && comments.length > 0) { for (int i = 0; i < comments.length; i++) { LinearLayout cl = new LinearLayout(Recorder.this); cl.setOrientation(LinearLayout.HORIZONTAL); cl.setPadding(0, 0, 0, pixel_5); debug.logD(TAG, "Refresher comment " + comments[i]); /* comment */ TextView comment_tv = new TextView(Recorder.this); comment_tv.setLayoutParams(params); comment_tv.setText(comments[i].get("username") + ": " + comments[i].get("comment"), TextView.BufferType.SPANNABLE); comment_tv.setTextColor(Color.parseColor("#656565")); Spannable comment_span = (Spannable) comment_tv.getText(); comment_span.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, comment_tv.getText().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); comment_span.setSpan(new ForegroundColorSpan(Color.parseColor("#182e5b")), 0, comments[i].get("username").length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); comment_tv.setText(comment_span); cl.addView(comment_tv); cc.addView(cl); } } else { if (mState == recorderState.RECORDING) { String msg = "You're LIVE! Your broadcast can be heard at http://flipzu.com/" + mUser.getUsername(); showFlipzuTipsOffline(cc, params, msg); } else { String msg = "Pick a good and descriptive broadcast title. A great title will attract more listeners!"; showFlipzuTipsOffline(cc, params, msg); msg = "You can disable sharing in Twitter and Facebook by clicking the logo buttons. This is great for testing."; showFlipzuTipsOffline(cc, params, msg); msg = "Press the \"Start Broadcast\" button and let them hear you!"; showFlipzuTipsOffline(cc, params, msg); } } }
From source file:com.heath_bar.tvdb.SeriesOverview.java
protected void ShowHideEpisodes(View seasonRow) { // Get the linear layout that we will be adding/removing the episodes to/from LinearLayout epLinearLayout = (LinearLayout) seasonRow; if (epLinearLayout.getChildCount() == 1) { // if collapsed, expand (add) the seasons TextView seasonText = (TextView) seasonRow.findViewById(R.id.season_text); seasonText.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.arrow_down), null, null, null);/*w ww .j ava 2 s. c o m*/ LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (int i = 0; i < episodeList.size(); i++) { if (seasonRow.getId() == episodeList.get(i).getSeason()) { View episodeView = inflater.inflate(R.layout.episode_text_row, epLinearLayout, false); episodeView.setBackgroundColor( AppSettings.listBackgroundColors[i % AppSettings.listBackgroundColors.length]); TextView text = (TextView) episodeView.findViewById(R.id.text); String nameText = String.format("%02d", episodeList.get(i).getNumber()) + " " + episodeList.get(i).getName(); text.setText(nameText); text.setTextSize(textSize); text.setId(episodeList.get(i).getId()); episodeView.setOnClickListener(episodeListener); epLinearLayout.addView(episodeView); } } } else { // else season is expanded, collapse it TextView seasonText = (TextView) seasonRow.findViewById(R.id.season_text); seasonText.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.arrow_right), null, null, null); for (int i = epLinearLayout.getChildCount() - 1; i > 0; i--) { epLinearLayout.removeView(epLinearLayout.getChildAt(i)); } } }
From source file:com.h6ah4i.android.example.materialshadowninepatch.ProgrammaticallyAddDemoFragment.java
private void addItem() { LinearLayout parent = mItemsContainer; Context context = parent.getContext(); float density = context.getResources().getDisplayMetrics().density; AppCompatTextView itemView = new AppCompatTextView(context); // Need to specify type of the shadow. Specify one of the following to the fourth parameter. ///*from w ww . j ava 2s. co m*/ // - R.style.ms9_DefaultShadowStyle[Z6|Z9|Z18] // - R.style.ms9_DefaultShadowStyle[Z6|Z9|Z18]CompatOnly // - R.style.ms9_NoDisplayedPositionAffectShadowStyle[Z6|Z9|Z18] // - R.style.ms9_NoDisplayedPositionAffectShadowStyle[Z6|Z9|Z18]CompatOnly // - R.style.ms9_CompositeShadowStyle[Z6|Z9|Z18] // - R.style.ms9_CompositeShadowStyle[Z6|Z9|Z18]CompatOnly MaterialShadowContainerView shadowView = new MaterialShadowContainerView(context, null, 0, R.style.ms9_DefaultShadowStyle); // Setup the itemView { MaterialShadowContainerView.LayoutParams layoutParams = new MaterialShadowContainerView.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, (int) (density * 56)); // Need to set background color and margins itemView.setBackgroundColor(Color.WHITE); layoutParams.setMargins((int) (8 * density), (int) (8 * density), (int) (8 * density), (int) (8 * density)); itemView.setLayoutParams(layoutParams); itemView.setText("Item " + (parent.getChildCount() + 1)); itemView.setGravity(Gravity.CENTER); } // Setup the shadowView { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); shadowView.setLayoutParams(layoutParams); shadowView.setShadowElevation(density * 4); shadowView.setForceUseCompatShadow(mCheckBoxForceUseCompatMode.isChecked()); } // Add views shadowView.addView(itemView); parent.addView(shadowView); }
From source file:jp.mau.twappremover.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { ScrollView contents = new ScrollView(this); LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); contents.addView(layout);//from ww w .java 2s . c o m AssetManager asm = getResources().getAssets(); String[] filelist = null; try { filelist = asm.list("licenses"); } catch (Exception ex) { ex.printStackTrace(); } if (filelist != null) { for (String file : filelist) { Gen.debug(file); InputStream is = null; BufferedReader br = null; String txt = ""; try { is = getAssets().open("licenses/" + file); br = new BufferedReader(new InputStreamReader(is)); String str; while ((str = br.readLine()) != null) { txt += str + "\n"; } } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (Exception ex) { } try { if (br != null) br.close(); } catch (Exception ex) { } } TextView tv = new TextView(this); tv.setText(txt); layout.addView(tv); } } // final PopupView dialog = new PopupView(this); dialog.setDialog().setLabels(getString(R.string.activity_main_dlgtitle_oss), "") .setView(contents, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) .setCancelable(true) .setPositiveBtn(getString(R.string.activity_main_dlgbtn_oss), new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }).show(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.alexive.graphicalutils.view.CardBuilder.java
public CardView build(Context context, CardView mCardView, boolean overrideBackground, boolean overrideElevation, boolean overrideRadius) { if (!mCardView.getTag(CARD_TYPE_TAG).equals(mCardType)) throw new IllegalArgumentException("Attempting to recycle a card of another type."); LinkedList<TextView> textViews = new LinkedList<>(); View view = mCardView.findViewById(android.R.id.text1); if (view != null) { view.setTag(true);//from w w w.j a v a2 s . c om textViews.add(((TextView) view)); ((TextView) view).setText(title); view.setVisibility(title != null ? View.VISIBLE : View.GONE); } view = mCardView.findViewById(android.R.id.text2); if (view != null) { textViews.add(((TextView) view)); ((TextView) view).setText(subTitle); view.setVisibility(subTitle != null ? View.VISIBLE : View.GONE); } view = mCardView.findViewById(R.id.content); if (view != null) { textViews.add(((TextView) view)); ((TextView) view).setText(text); view.setVisibility(text != null ? View.VISIBLE : View.GONE); } mCardView.setOnClickListener(mPrimaryAction); //TODO add the custom view FrameLayout mCustomViewParent = (FrameLayout) mCardView.findViewById(R.id.custom_view_container); if (mCustomViewParent != null) { mCustomViewParent.removeAllViews(); if (customMainView != null) mCustomViewParent.addView(customMainView); } view = mCardView.findViewById(android.R.id.content); if (view != null) { if (image instanceof Bitmap) ((ImageView) view).setImageBitmap((Bitmap) image); else if (image instanceof Drawable) ((ImageView) view).setImageDrawable((Drawable) image); else ((ImageView) view).setImageDrawable(null); } LinearLayout mActionContainer = (LinearLayout) mCardView.findViewById(R.id.action_container); if (actions.isEmpty()) mActionContainer.setVisibility(View.GONE); else { mActionContainer.setVisibility(View.VISIBLE); for (int i = 0; i < actions.size(); i++) { CardAction action = actions.get(i); // int j = i; // View optimalView = null; // Needs to be rewriten // while (j < mActionContainer.getChildCount()) { // optimalView = mActionContainer.getChildAt(j); // if ((action.drawable != null && optimalView instanceof ImageButton) || (action.title != // null && optimalView instanceof Button)) { // mActionContainer.removeViewAt(j); // mActionContainer.addView(optimalView, i); // break; // } else { // optimalView = null; // j++; // } // } // if (optimalView == null) { View actionView = null; if (action.title != null) { Button button = (Button) LayoutInflater.from(context).inflate(R.layout.card_bttn, null); textViews.add(button); button.setText(action.title); button.setOnClickListener(this); mActionContainer.addView(button); actionView = button; } else if (action.drawable != null) { ImageButton imageButton = (ImageButton) LayoutInflater.from(context) .inflate(R.layout.card_image_bttn, null); imageButton.setImageDrawable(action.drawable); imageButton.setOnClickListener(this); mActionContainer.addView(imageButton); actionView = imageButton; } //NASTY workaround for the padding View space = new View(context); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( ViewUtils.convertDPtoPixels(context, 8), ViewUtils.convertDPtoPixels(context, 8)); mActionContainer.addView(space, params); assert actionView != null; actionView.setTag(ACTION_ID_TAG, action); } } if (useLightTheme) { if (overrideBackground) mCardView.setCardBackgroundColor(0xFFFFFF); setTextColor(textViews, ContextCompat.getColor(context, android.R.color.primary_text_light), ContextCompat.getColor(context, android.R.color.secondary_text_light)); } else { if (overrideBackground) mCardView.setCardBackgroundColor(0x424242); setTextColor(textViews, ContextCompat.getColor(context, android.R.color.primary_text_dark), ContextCompat.getColor(context, android.R.color.secondary_text_dark)); } //Material design guidelines: 2dp resting elevation (or 8dp when raised) //Let's assume the card is resting //Also: 2dp corner radius int dPtoPixels = ViewUtils.convertDPtoPixels(context, 2); if (overrideElevation) mCardView.setCardElevation(dPtoPixels); if (overrideRadius) mCardView.setRadius(dPtoPixels); return mCardView; }
From source file:com.mobilevue.vod.VideoControllerView.java
private void updateChannels(View v, List<ChannelData> result) { int imgno = 0; LinearLayout channels = (LinearLayout) v.findViewById(R.id.a_video_ll_channels); SharedPreferences mPrefs = mContext.getSharedPreferences(IPTVActivity.PREFS_FILE, 0); final Editor editor = mPrefs.edit(); for (final ChannelData data : result) { editor.putString(data.getChannelName(), data.getUrl()); editor.commit();/*from w w w .ja v a2s .com*/ imgno += 1; ChannelInfo chInfo = new ChannelInfo(data.getChannelName(), data.getUrl()); final ImageButton button = new ImageButton(mContext); LayoutParams params = new LayoutParams(Gravity.CENTER, Gravity.CENTER); params.height = 96; params.width = 96; params.setMargins(1, 1, 1, 1); button.setLayoutParams(params);// new LinearLayout.LayoutParams(66, // 66)); button.setId(1000 + imgno); button.setTag(chInfo); button.setFocusable(false); button.setFocusableInTouchMode(false); ImageLoader.getInstance().displayImage(data.getImage(), button); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ChannelInfo info = (ChannelInfo) v.getTag(); mPlayer.changeChannel(Uri.parse(info.channelURL)); // updatePausePlay(); // show(sDefaultTimeout); } }); channels.addView(button); } }
From source file:fr.gotorennes.AbstractMapActivity.java
protected void populateItineraireDetails(Itineraire itineraire) { LinearLayout details = (LinearLayout) findViewById(R.id.details); for (final Etape etape : itineraire.etapes) { addEtapeOverlay(etape);//w ww . jav a 2s . co m RelativeLayout view = (RelativeLayout) getLayoutInflater().inflate(R.layout.itineraire_listitem, null); ImageView lineIcon = (ImageView) view.findViewById(R.id.icon); if (etape.bitmapIcon != null) { lineIcon.setImageBitmap(etape.bitmapIcon); } else { lineIcon.setImageResource(etape.type.icon); } TextView name = (TextView) view.findViewById(R.id.name); name.setText(Html.fromHtml(Arret.getTime(etape.depart) + " : " + etape.adresseDepart + "<br />" + Arret.getTime(etape.arrivee) + " : " + etape.adresseArrivee)); TextView duree = (TextView) view.findViewById(R.id.duree); duree.setText(etape.getDuree() + "min"); TextView distance = (TextView) view.findViewById(R.id.distance); distance.setText(getFormattedDistance(etape.locationDepart, etape.locationArrivee)); distance.setVisibility( etape.type == TypeEtape.PIETON || etape.type == TypeEtape.VELO ? View.VISIBLE : View.GONE); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Location depart = etape.locationDepart; centerMap(depart.latitude, depart.longitude); } }); details.addView(view); } Location first = itineraire.etapes.get(0).locationDepart; centerMap(first.latitude, first.longitude); }
From source file:com.mdlive.sav.MDLiveProviderDetails.java
private void phsOnlyForPhone() { saveAppmtType("phone"); byvideoBtnLayout.setBackgroundResource(R.drawable.disable_round_rect_grey_border); byvideoBtn.setTextColor(getResources().getColor(R.color.disableBtn)); ((ImageView) findViewById(R.id.videoicon)).setImageResource(R.drawable.video_icon_gray); byvideoBtnLayout.setVisibility(View.VISIBLE); byvideoBtnLayout.setClickable(false); byphoneBtnLayout.setVisibility(View.VISIBLE); byphoneBtnLayout.setOnClickListener(new View.OnClickListener() { @Override/* w w w. ja va 2 s . c o m*/ public void onClick(View v) { try { horizontalscrollview.smoothScrollTo(layout.getChildAt(0).getLeft(), 0); byphoneBtnLayout.setBackgroundResource(R.drawable.searchpvr_blue_rounded_corner); byphoneBtn.setTextColor(Color.WHITE); ((ImageView) findViewById(R.id.phoneicon)).setImageResource(R.drawable.phone_icon_white); ((ImageView) findViewById(R.id.videoicon)).setImageResource(R.drawable.video_icon_gray); horizontalscrollview.setVisibility(View.VISIBLE); byvideoBtnLayout.setVisibility(View.VISIBLE); byvideoBtnLayout.setBackgroundResource(R.drawable.disable_round_rect_grey_border); byvideoBtn.setTextColor(getResources().getColor(R.color.disableBtn)); byvideoBtnLayout.setClickable(false); LinearLayout layout = (LinearLayout) findViewById(R.id.panelMessageFiles); if (layout.getChildCount() > 0) { layout.removeAllViews(); } for (TextView tv : phoneList) { layout.addView(tv); } saveConsultationType("Phone", MDLiveProviderDetails.this); //Enable Request Appointment Button enableReqAppmtBtn(); horizontalscrollview.smoothScrollTo(layout.getChildAt(0).getLeft(), 0); ((ImageView) findViewById(R.id.phoneicon)).setImageResource(R.drawable.phone_icon_white); selectedTimeslot = false; enableReqAppmtBtn(); clearTimeSlotViews(); horizontalscrollview.startAnimation( AnimationUtils.loadAnimation(MDLiveProviderDetails.this, R.anim.mdlive_trans_left_in)); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:com.mdlive.sav.MDLiveProviderDetails.java
private void onlyForIdaho() { byphoneBtnLayout.setVisibility(View.VISIBLE); byphoneBtnLayout.setBackgroundResource(R.drawable.disable_round_rect_grey_border); byphoneBtn.setTextColor(getResources().getColor(R.color.disableBtn)); ((ImageView) findViewById(R.id.phoneicon)).setImageResource(R.drawable.phone_icon_gray); byphoneBtnLayout.setClickable(false); saveAppmtType("video"); byvideoBtnLayout.setBackgroundResource(R.drawable.searchpvr_white_rounded_corner); byvideoBtn.setTextColor(Color.GRAY); byvideoBtn.setTextColor(Color.GRAY); byvideoBtnLayout.setVisibility(View.VISIBLE); byvideoBtnLayout.setOnClickListener(new View.OnClickListener() { @Override//from www. j a v a 2 s .co m public void onClick(View v) { try { horizontalscrollview.smoothScrollTo(layout.getChildAt(0).getLeft(), 0); byvideoBtnLayout.setBackgroundResource(R.drawable.searchpvr_blue_rounded_corner); byvideoBtn.setTextColor(Color.WHITE); ((ImageView) findViewById(R.id.videoicon)).setImageResource(R.drawable.video_icon_white); ((ImageView) findViewById(R.id.phoneicon)).setImageResource(R.drawable.phone_icon_gray); byphoneBtnLayout.setBackgroundResource(R.drawable.disable_round_rect_grey_border); byphoneBtn.setTextColor(getResources().getColor(R.color.disableBtn)); byphoneBtnLayout.setVisibility(View.VISIBLE); byphoneBtnLayout.setClickable(false); horizontalscrollview.setVisibility(View.VISIBLE); LinearLayout layout = (LinearLayout) findViewById(R.id.panelMessageFiles); if (layout.getChildCount() > 0) { layout.removeAllViews(); } for (TextView tv : videoList) { layout.addView(tv); } saveConsultationType("Video", MDLiveProviderDetails.this); //Enable Request Appointment Button horizontalscrollview.smoothScrollTo(layout.getChildAt(0).getLeft(), 0); ((ImageView) findViewById(R.id.videoicon)).setImageResource(R.drawable.video_icon_white); selectedTimeslot = false; enableReqAppmtBtn(); clearTimeSlotViews(); horizontalscrollview.startAnimation( AnimationUtils.loadAnimation(MDLiveProviderDetails.this, R.anim.mdlive_trans_left_in)); } catch (Exception e) { e.printStackTrace(); } } }); }