List of usage examples for android.widget ImageView setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:com.inter.trade.view.slideplayview.AbSlidingPlayView.java
/** * ./*from w w w. ja v a2 s . c o m*/ */ public void creatIndex() { //? pageLineLayout.removeAllViews(); mPageLineLayoutParent.setHorizontalGravity(pageLineHorizontalGravity); pageLineLayout.setGravity(Gravity.CENTER); pageLineLayout.setVisibility(View.VISIBLE); count = mListViews.size(); for (int j = 0; j < count; j++) { ImageView imageView = new ImageView(context); pageLineLayoutParams.setMargins(5, 5, 5, 5); imageView.setLayoutParams(pageLineLayoutParams); if (j == 0) { imageView.setImageBitmap(displayImage); } else { imageView.setImageBitmap(hideImage); } pageLineLayout.addView(imageView, j); } }
From source file:com.markupartist.sthlmtraveling.ui.view.TripView.java
public void updateViews() { this.setOrientation(VERTICAL); float scale = getResources().getDisplayMetrics().density; this.setPadding(getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding), getResources().getDimensionPixelSize(R.dimen.list_vertical_padding), getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding), getResources().getDimensionPixelSize(R.dimen.list_vertical_padding)); LinearLayout timeStartEndLayout = new LinearLayout(getContext()); TextView timeStartEndText = new TextView(getContext()); timeStartEndText.setText(DateTimeUtil.routeToTimeDisplay(getContext(), trip)); timeStartEndText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1)); timeStartEndText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); ViewCompat.setPaddingRelative(timeStartEndText, 0, 0, 0, (int) (2 * scale)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (RtlUtils.isRtl(Locale.getDefault())) { timeStartEndText.setTextDirection(View.TEXT_DIRECTION_RTL); }// www.ja v a 2 s . c o m } // Check if we have Realtime for start and or end. boolean hasRealtime = false; Pair<Date, RealTimeState> transitTime = trip.departsAt(true); if (transitTime.second != RealTimeState.NOT_SET) { hasRealtime = true; } else { transitTime = trip.arrivesAt(true); if (transitTime.second != RealTimeState.NOT_SET) { hasRealtime = true; } } // if (hasRealtime) { // ImageView liveDrawable = new ImageView(getContext()); // liveDrawable.setImageResource(R.drawable.ic_live); // ViewCompat.setPaddingRelative(liveDrawable, 0, (int) (2 * scale), (int) (4 * scale), 0); // timeStartEndLayout.addView(liveDrawable); // // AlphaAnimation animation1 = new AlphaAnimation(0.4f, 1.0f); // animation1.setDuration(600); // animation1.setRepeatMode(Animation.REVERSE); // animation1.setRepeatCount(Animation.INFINITE); // // liveDrawable.startAnimation(animation1); // } timeStartEndLayout.addView(timeStartEndText); LinearLayout startAndEndPointLayout = new LinearLayout(getContext()); TextView startAndEndPoint = new TextView(getContext()); BidiFormatter bidiFormatter = BidiFormatter.getInstance(RtlUtils.isRtl(Locale.getDefault())); startAndEndPoint.setText(String.format("%s %s", bidiFormatter.unicodeWrap(trip.fromStop().getName()), bidiFormatter.unicodeWrap(trip.toStop().getName()))); startAndEndPoint.setTextColor(getResources().getColor(R.color.body_text_1)); // Dark gray startAndEndPoint.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (RtlUtils.isRtl(Locale.getDefault())) { startAndEndPoint.setTextDirection(View.TEXT_DIRECTION_RTL); } } ViewCompat.setPaddingRelative(startAndEndPoint, 0, (int) (4 * scale), 0, (int) (4 * scale)); startAndEndPointLayout.addView(startAndEndPoint); RelativeLayout timeLayout = new RelativeLayout(getContext()); LinearLayout routeChanges = new LinearLayout(getContext()); routeChanges.setGravity(Gravity.CENTER_VERTICAL); LinearLayout.LayoutParams changesLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); changesLayoutParams.gravity = Gravity.CENTER_VERTICAL; if (trip.hasAlertsOrNotes()) { ImageView warning = new ImageView(getContext()); warning.setImageResource(R.drawable.ic_trip_deviation); ViewCompat.setPaddingRelative(warning, 0, (int) (2 * scale), (int) (4 * scale), 0); routeChanges.addView(warning); } int currentTransportCount = 1; int transportCount = trip.getLegs().size(); for (Leg leg : trip.getLegs()) { if (!leg.isTransit() && transportCount > 3) { if (leg.getDistance() < 150) { continue; } } if (currentTransportCount > 1 && transportCount >= currentTransportCount) { ImageView separator = new ImageView(getContext()); separator.setImageResource(R.drawable.transport_separator); ViewCompat.setPaddingRelative(separator, 0, 0, (int) (2 * scale), 0); separator.setLayoutParams(changesLayoutParams); routeChanges.addView(separator); if (RtlUtils.isRtl(Locale.getDefault())) { ViewCompat.setScaleX(separator, -1f); } } ImageView changeImageView = new ImageView(getContext()); Drawable transportDrawable = LegUtil.getTransportDrawable(getContext(), leg); changeImageView.setImageDrawable(transportDrawable); if (RtlUtils.isRtl(Locale.getDefault())) { ViewCompat.setScaleX(changeImageView, -1f); } ViewCompat.setPaddingRelative(changeImageView, 0, 0, 0, 0); changeImageView.setLayoutParams(changesLayoutParams); routeChanges.addView(changeImageView); if (currentTransportCount <= 3) { String lineName = leg.getRouteShortName(); if (!TextUtils.isEmpty(lineName)) { TextView lineNumberView = new TextView(getContext()); lineNumberView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13); RoundedBackgroundSpan roundedBackgroundSpan = new RoundedBackgroundSpan( LegUtil.getColor(getContext(), leg), Color.WHITE, ViewHelper.dipsToPix(getContext().getResources(), 4)); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(lineName); sb.append(' '); sb.setSpan(roundedBackgroundSpan, 0, lineName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); lineNumberView.setText(sb); ViewCompat.setPaddingRelative(lineNumberView, (int) (5 * scale), (int) (1 * scale), (int) (2 * scale), 0); lineNumberView.setLayoutParams(changesLayoutParams); routeChanges.addView(lineNumberView); } } currentTransportCount++; } TextView durationText = new TextView(getContext()); durationText.setText(DateTimeUtil.formatDetailedDuration(getResources(), trip.getDuration() * 1000)); durationText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1)); durationText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); durationText.setTypeface(Typeface.DEFAULT_BOLD); timeLayout.addView(routeChanges); timeLayout.addView(durationText); RelativeLayout.LayoutParams durationTextParams = (RelativeLayout.LayoutParams) durationText .getLayoutParams(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_END); } else { durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } durationText.setLayoutParams(durationTextParams); View divider = new View(getContext()); ViewGroup.LayoutParams dividerParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); divider.setLayoutParams(dividerParams); this.addView(timeLayout); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) routeChanges.getLayoutParams(); params.height = LayoutParams.MATCH_PARENT; params.addRule(RelativeLayout.CENTER_VERTICAL); routeChanges.setLayoutParams(params); this.addView(startAndEndPointLayout); this.addView(timeStartEndLayout); if (mShowDivider) { this.addView(divider); } }
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;/*from w w w. jav a 2 s .co 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.alex.view.loop.IndicatorView.java
/** * //from ww w .j av a 2 s .co m * * @return */ private View makeIndicatorItem() { ImageView iv = new ImageView(getContext()); LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); lp.width = normalBp.getWidth(); lp.height = normalBp.getHeight(); lp.rightMargin = mInterval; iv.setImageBitmap(normalBp); iv.setLayoutParams(lp); return iv; }
From source file:org.catnut.plugin.zhihu.ZhihuItemFragment.java
private ImageView getImageView() { ImageView image = new ImageView(getActivity()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.setMargins(0, 10, 0, 10);/* w w w .j ava2 s . co m*/ image.setLayoutParams(lp); image.setAdjustViewBounds(true); image.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return CatnutUtils.imageOverlay(v, event); } }); image.setOnClickListener(this); return image; }
From source file:uk.org.downiesoft.slideshow.ThumbnailAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView; if (convertView == null) { imageView = (ImageView) mLayoutInflater.inflate(R.layout.gridview_item, parent, false); imageView.setLayoutParams(mLayoutParams); } else {/*w w w . j a va2 s . c o m*/ imageView = (ImageView) convertView; // hack to reset selection state of re-used views after action mode ended AbsListView list = (AbsListView) parent; if (list != null && list.getChoiceMode() == ListView.CHOICE_MODE_NONE) { imageView.setActivated(false); } } if (mThumbBitmaps.size() > position && mThumbBitmaps.get(position) != null) { Bitmap bmp = mThumbBitmaps.get(position); imageView.setImageBitmap(bmp); if (bmp.getWidth() >= mThumbSize || bmp.getHeight() >= mThumbSize) { imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); } else { imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); } } else { imageView.setImageResource(R.drawable.ic_launcher); } return imageView; }
From source file:br.org.funcate.dynamicforms.views.GPictureView.java
private ImageView getImageView(final Context context, Bitmap photo, String uuid) { ImageView imageView = new ImageView(context); imageView.setLayoutParams(new LinearLayout.LayoutParams(thumbnailWidth, thumbnailHeight)); imageView.setPadding(5, 5, 5, 5);/*from w w w .j a v a 2 s . c om*/ imageView.setImageBitmap(photo); imageView.setBackgroundDrawable(getResources().getDrawable(R.drawable.border_black_1px)); imageView.setTag(uuid); imageView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String photoId = (String) v.getTag(); FragmentActivity activity = mFragmentDetail.getActivity(); Intent intent = new Intent(activity, PictureActivity.class); if (addedIdsToImageViews.containsKey(photoId)) {// pictures on session intent.putExtra(FormUtilities.PICTURE_PATH_VIEW, addedIdsToImageViews.get(photoId)); } else if (_pictures.containsKey(photoId)) {// pictures from database Map<String, String> imagePaths = _pictures.get(photoId); String imagePath = imagePaths.get("display"); intent.putExtra(FormUtilities.PICTURE_DB_VIEW, imagePath);// Image temporary path } if (intent.hasExtra(FormUtilities.PICTURE_PATH_VIEW) || intent.hasExtra(FormUtilities.PICTURE_DB_VIEW)) { intent.putExtra(FormUtilities.PICTURE_BITMAP_ID, photoId); activity.startActivityForResult(intent, PICTURE_VIEW_RESULT); } else Toast.makeText(getContext(), "Fail, the picture not found.", Toast.LENGTH_LONG).show(); /* JSONArray form = null; try { form = mFragmentDetail.getSelectedForm(); } catch (JSONException jse) { jse.printStackTrace(); Toast.makeText(getContext(), jse.getMessage(), Toast.LENGTH_LONG).show(); } if (form != null) { try { String json = encodeToJson(); FormUtilities.updatePicture(form, json); } catch (JSONException e) { e.printStackTrace(); }catch (Exception e) { e.printStackTrace(); } } try { refresh(getContext()); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); }*/ /** * open in markers to edit it */ // MarkersUtilities.launchOnImage(context, image); /* try { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); Image image = imagesDbHelper.getImage(imageIdLong); File tempDir = ResourcesManager.getInstance(context).getTempDir(); String ext = ".jpg"; if (image.getName().endsWith(".png")) ext = ".png"; File imageFile = new File(tempDir, ImageUtilities.getTempImageName(ext)); byte[] imageData = imagesDbHelper.getImageData(image.getId()); ImageUtilities.writeImageDataToFile(imageData, imageFile.getAbsolutePath()); intent.setDataAndType(Uri.fromFile(imageFile), "image*//**//*"); //$NON-NLS-1$ context.startActivity(intent); } catch (Exception e) { //GPLog.error(this, null, e); Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); }*/ //Toast.makeText(getContext(), "Implement this action", Toast.LENGTH_LONG).show(); } }); return imageView; }
From source file:com.tony.selene.sliding.AbSlidingPlayView.java
/** * ./* w w w. jav a 2 s. co m*/ */ public void creatIndex() { // ? navLinearLayout.removeAllViews(); mNavLayoutParent.setHorizontalGravity(navHorizontalGravity); navLinearLayout.setGravity(Gravity.CENTER); navLinearLayout.setVisibility(View.VISIBLE); count = mListViews.size(); navLayoutParams.setMargins(5, 5, 5, 5); navLayoutParams.width = 15; navLayoutParams.height = 15; for (int j = 0; j < count; j++) { ImageView imageView = new ImageView(context); imageView.setLayoutParams(navLayoutParams); if (j == 0) { imageView.setImageDrawable(displayDrawable); } else { imageView.setImageDrawable(hideDrawable); } AbViewUtil.scaleView(imageView); navLinearLayout.addView(imageView, j); } }
From source file:com.lxh.util.pullview.AbSlidingPlayView.java
/** * .//from w w w . j a va2s . c o m */ public void creatIndex() { // ? navLinearLayout.removeAllViews(); mNavLayoutParent.setHorizontalGravity(navHorizontalGravity); navLinearLayout.setGravity(Gravity.CENTER); navLinearLayout.setVisibility(View.VISIBLE); count = mListViews.size(); navLayoutParams.setMargins(5, 5, 5, 5); for (int j = 0; j < count; j++) { ImageView imageView = new ImageView(context); imageView.setLayoutParams(navLayoutParams); if (j == 0) { imageView.setImageBitmap(displayImage); } else { imageView.setImageBitmap(hideImage); } navLinearLayout.addView(imageView, j); } }
From source file:com.tundem.alternativefindr.ApplicationActivity.java
public void init_application(View v) { WebImageView alternative_icon = ((WebImageView) v.findViewById(R.id.alternative_icon)); TextView alternative_votes = ((TextView) v.findViewById(R.id.alternative_votes)); TextView alternative_name = ((TextView) v.findViewById(R.id.alternative_name)); TextView alternative_license = ((TextView) v.findViewById(R.id.alternative_license)); LinearLayout alternative_platforms = ((LinearLayout) v.findViewById(R.id.alternative_platforms_container)); //TextView alternative_description = ((TextView) v.findViewById(R.id.alternative_description)); /* Set ImageView */ alternative_icon.setImageUrl(mApplication.getIconUrl()); /* Set Texts */ alternative_votes.setText(String.valueOf(mApplication.getVotes()) + "\nVotes"); alternative_name.setText(mApplication.getName()); alternative_license.setText(mApplication.getLicense()); //alternative_description.setText(application.getShortDescription()); if (mApplication.getPlatforms() != null) { List<Integer> resIds = new LinkedList<Integer>(); for (String s : mApplication.getPlatforms()) { if (!TextUtils.isEmpty(s)) { int resId = getResId(s.toLowerCase()); if (!resIds.contains(resId) && resId != -1) resIds.add(resId);//from ww w.j a v a2 s . c o m } } for (Integer resId : resIds) { ImageView iv = new ImageView(this); iv.setScaleType(ScaleType.FIT_CENTER); float sizeInDip = 18f; int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeInDip, this.getResources().getDisplayMetrics()); LayoutParams lp = new LayoutParams(padding, padding); iv.setLayoutParams(lp); iv.setImageResource(resId); alternative_platforms.addView(iv); } } }