List of usage examples for android.widget ImageView setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:com.google.reviewit.AddReviewerFragment.java
private void addReviewerRow(TableLayout tl, AccountInfo reviewer) { TableRow tr = new TableRow(getContext()); tr.setLayoutParams(matchAndWrapTableRowLayout()); ImageView avatar = new ImageView(getContext()); TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(widgetUtil.dpToPx(20), widgetUtil.dpToPx(20));//from ww w.ja va 2 s .c om layoutParams.setMargins(0, 0, widgetUtil.dpToPx(5), widgetUtil.dpToPx(2)); avatar.setLayoutParams(layoutParams); WidgetUtil.displayAvatar(getApp(), reviewer, avatar); tr.addView(avatar); TextView reviewerName = new TextView(getContext()); reviewerName.setLayoutParams(wrapTableRowLayout()); reviewerName.setText(FormatUtil.format(reviewer)); tr.addView(reviewerName); tl.addView(tr, matchAndWrapTableLayout()); }
From source file:org.alfresco.mobile.android.application.fragments.site.browser.SitesFragment.java
@Override protected void prepareEmptyView(View ev, ImageView emptyImageView, TextView firstEmptyMessage, TextView secondEmptyMessage) {// ww w . j a v a2s .c o m if (keywords == null) { emptyImageView.setImageResource( isFavoriteListing ? R.drawable.ic_empty_sites_favorite : R.drawable.ic_empty_sites_my); emptyImageView.setLayoutParams(DisplayUtils.resizeLayout(getActivity(), 275, 275)); firstEmptyMessage.setText( isFavoriteListing ? R.string.sites_favorites_empty_title : R.string.sites_my_empty_title); secondEmptyMessage.setVisibility(View.VISIBLE); secondEmptyMessage.setText(isFavoriteListing ? R.string.sites_favorites_empty_description : R.string.sites_my_empty_description); } else { emptyImageView.setLayoutParams(DisplayUtils.resizeLayout(getActivity(), 275, 275)); emptyImageView.setImageResource(R.drawable.ic_empty_search_sites); firstEmptyMessage.setVisibility(View.VISIBLE); firstEmptyMessage.setText(R.string.sites_search_empty_title); secondEmptyMessage.setVisibility(View.VISIBLE); secondEmptyMessage.setText(R.string.sites_search_empty_description); } }
From source file:com.saulmm.cui.OrderDialogFragment.java
private View createSelectedColorView(ImageView selectedView) { final ImageView fakeImageView = new CircleImageView(getContext(), null, R.attr.colorStyle); fakeImageView.setImageDrawable(selectedView.getDrawable()); fakeImageView.setLayoutParams(SelectedParamsFactory.startColorParams(selectedView)); return fakeImageView; }
From source file:mobisocial.musubi.objects.WebAppObj.java
@Override public View createView(Context context, ViewGroup parent) { LinearLayout frame = new LinearLayout(context); frame.setLayoutParams(CommonLayouts.FULL_WIDTH); frame.setOrientation(LinearLayout.VERTICAL); LinearLayout appBar = new LinearLayout(context); appBar.setLayoutParams(CommonLayouts.FULL_WIDTH); appBar.setOrientation(LinearLayout.HORIZONTAL); frame.addView(appBar);//from ww w. j a v a 2 s . com Drawable icon = context.getResources().getDrawable(R.drawable.ic_menu_globe); ImageView iv = new ImageView(context); iv.setImageDrawable(icon); iv.setAdjustViewBounds(true); iv.setMaxWidth(60); iv.setMaxHeight(60); iv.setLayoutParams(CommonLayouts.WRAPPED); appBar.addView(iv); TextView tv = new TextView(context); tv.setLayoutParams(CommonLayouts.WRAPPED); tv.setGravity(Gravity.CENTER_VERTICAL); appBar.addView(tv); LinearLayout actionBar = new LinearLayout(context); actionBar.setLayoutParams(CommonLayouts.WRAPPED); actionBar.setOrientation(LinearLayout.HORIZONTAL); frame.addView(actionBar); Button b = new Button(context); // required for listview long-press b.setLayoutParams(CommonLayouts.WRAPPED); b.setFocusable(false); b.setText("Run"); b.setOnClickListener(getRunListener()); actionBar.addView(b); b = new Button(context); // required for listview long-press b.setLayoutParams(CommonLayouts.WRAPPED); b.setFocusable(false); b.setOnClickListener(getAddListener()); actionBar.addView(b); return frame; }
From source file:Main.java
public static void scaleImage(ImageView view, int boundBoxInDp) { // Get the ImageView and its bitmap Drawable drawing = view.getDrawable(); Bitmap bitmap = ((BitmapDrawable) drawing).getBitmap(); // Get current dimensions int width = bitmap.getWidth(); int height = bitmap.getHeight(); // Determine how much to scale: the dimension requiring less scaling is // closer to the its side. This way the image always stays inside your // bounding box AND either x/y axis touches it. float xScale = ((float) boundBoxInDp) / width; float yScale = ((float) boundBoxInDp) / height; float scale = (xScale <= yScale) ? xScale : yScale; // Create a matrix for the scaling and add the scaling data Matrix matrix = new Matrix(); matrix.postScale(scale, scale);/* www. j a va 2s .c o m*/ // Create a new bitmap and convert it to a format understood by the ImageView Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); BitmapDrawable result = new BitmapDrawable(scaledBitmap); width = scaledBitmap.getWidth(); height = scaledBitmap.getHeight(); // Apply the scaled bitmap view.setImageDrawable(result); // Now change ImageView's dimensions to match the scaled image LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); params.width = width; params.height = height; view.setLayoutParams(params); }
From source file:com.example.meetingapp.ShowDetailsFragment.java
/** * Adds an image to the HorizontalScrollView. * @param image Image to be added to the HorizontalScrollView. *///from w ww . ja v a 2s .c om private void addImage(Bitmap image) { LinearLayout layout = new LinearLayout(getActivity()); layout.setGravity(Gravity.CENTER); /* Set parameters - we want a small divider of 3 pixels so we can * easily distinguish different photos. */ LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.setMargins(3, 0, 0, 0); params.gravity = Gravity.CENTER; ImageView imageView = new ImageView(getActivity()); imageView.setScaleType(ScaleType.CENTER); imageView.setImageBitmap(image); imageView.setLayoutParams(params); layout.addView(imageView); mPhotosView.addView(layout); }
From source file:com.loongsoft.qingzhou.WelcomeActivity.java
private void addDot() { ImageView dotImageView = new ImageView(this); dotImageView.setImageDrawable(getResources().getDrawable(R.drawable.welcome_dot_normal)); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(15, 15); params.setMargins(5, 5, 5, 5);/* w w w . j ava2 s . c om*/ dotImageView.setLayoutParams(params); LinearLayout welcome_dots_layout = (LinearLayout) findViewById(R.id.welcome_dots); welcome_dots_layout.addView(dotImageView); mDots.add(dotImageView); }
From source file:com.android.ted.sample.viewpager.MainPagerAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { View itemView;/*w ww . j a v a2 s. c o m*/ Girl girl = mAllGirlList.get(position); if (mAllImageMap.containsKey(position)) { View oldView = mAllImageMap.get(position); Object tag = oldView.getTag(); if (null != tag && tag instanceof Girl) { if (tag.equals(girl)) { itemView = oldView; container.addView(itemView); return itemView; } } container.removeView(oldView); mAllImageMap.remove(position); } ImageView imageView = new ImageView(mContext); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); Glide.with(mContext).load(girl.getImageUrl()).into(imageView); imageView.setTag(girl); ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); imageView.setLayoutParams(layoutParams); mAllImageMap.put(position, imageView); itemView = imageView; itemView.setOnClickListener(this); container.addView(itemView); return itemView; }
From source file:com.esri.arcgisruntime.sample.featurelayerupdateattributes.MainActivity.java
/** * Displays Callout/*w w w. j av a 2s .c o m*/ * @param title the text to show in the Callout */ private void showCallout(String title) { // create a text view for the callout RelativeLayout calloutLayout = new RelativeLayout(getApplicationContext()); TextView calloutContent = new TextView(getApplicationContext()); calloutContent.setId(R.id.textview); calloutContent.setTextColor(Color.BLACK); calloutContent.setTextSize(18); calloutContent.setPadding(0, 10, 10, 0); calloutContent.setText(title); RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); relativeParams.addRule(RelativeLayout.RIGHT_OF, calloutContent.getId()); // create image view for the callout ImageView imageView = new ImageView(getApplicationContext()); imageView.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_info_outline_black_18dp)); imageView.setLayoutParams(relativeParams); imageView.setOnClickListener(new ImageViewOnclickListener()); calloutLayout.addView(calloutContent); calloutLayout.addView(imageView); mCallout.setLocation(mMapView.screenToLocation(mClickPoint)); mCallout.setContent(calloutLayout); mCallout.show(); }
From source file:at.alladin.rmbt.android.map.overlay.RMBTBalloonOverlayView.java
public void setBalloonData(final RMBTBalloonOverlayItem item, final ViewGroup parent) { // map our custom item data to fields // title.setText(item.getTitle()); resultItems = item.getResultItems(); resultListView.removeAllViews();/*from w w w . j a va 2 s . c om*/ final float scale = getResources().getDisplayMetrics().density; final int leftRightItem = Helperfunctions.dpToPx(5, scale); final int topBottomItem = Helperfunctions.dpToPx(3, scale); final int leftRightDiv = Helperfunctions.dpToPx(0, scale); final int topBottomDiv = Helperfunctions.dpToPx(0, scale); final int heightDiv = Helperfunctions.dpToPx(1, scale); final int topBottomImg = Helperfunctions.dpToPx(1, scale); if (resultItems != null && resultItems.length() > 0) { for (int i = 0; i < 1; i++) // JSONObject resultListItem; try { final JSONObject result = resultItems.getJSONObject(i); final LayoutInflater resultInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View resultView = resultInflater.inflate(R.layout.balloon_overlay_listitem, parent); final LinearLayout measurementLayout = (LinearLayout) resultView .findViewById(R.id.resultMeasurementList); measurementLayout.setVisibility(View.GONE); final LinearLayout netLayout = (LinearLayout) resultView.findViewById(R.id.resultNetList); netLayout.setVisibility(View.GONE); final TextView measurementHeader = (TextView) resultView.findViewById(R.id.resultMeasurement); measurementHeader.setVisibility(View.GONE); final TextView netHeader = (TextView) resultView.findViewById(R.id.resultNet); netHeader.setVisibility(View.GONE); final TextView dateHeader = (TextView) resultView.findViewById(R.id.resultDate); dateHeader.setVisibility(View.GONE); dateHeader.setText(result.optString("time_string")); final JSONArray measurementArray = result.getJSONArray("measurement"); final JSONArray netArray = result.getJSONArray("net"); for (int j = 0; j < measurementArray.length(); j++) { final JSONObject singleItem = measurementArray.getJSONObject(j); final LinearLayout measurememtItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item); measurememtItemLayout.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); measurememtItemLayout.setGravity(Gravity.CENTER_VERTICAL); measurememtItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem); final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle); itemTitle.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f)); itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle); itemTitle.setWidth(0); itemTitle.setGravity(Gravity.LEFT); itemTitle.setText(singleItem.getString("title")); measurememtItemLayout.addView(itemTitle); final ImageView itemClassification = new ImageView(context); itemClassification.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f)); itemClassification.setPadding(0, topBottomImg, 0, topBottomImg); // itemClassification.set setGravity(Gravity.LEFT); itemClassification.setImageDrawable(getResources().getDrawable( Helperfunctions.getClassificationImage(singleItem.getInt("classification")))); measurememtItemLayout.addView(itemClassification); final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue); itemValue.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f)); itemValue.setTextAppearance(context, R.style.balloonResultItemValue); itemValue.setWidth(0); itemValue.setGravity(Gravity.LEFT); itemValue.setText(singleItem.getString("value")); measurememtItemLayout.addView(itemValue); measurementLayout.addView(measurememtItemLayout); final View divider = new View(context); divider.setLayoutParams(new LinearLayout.LayoutParams( android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1)); divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv); divider.setBackgroundResource(R.drawable.bg_trans_light_10); measurementLayout.addView(divider); measurementLayout.invalidate(); } for (int j = 0; j < netArray.length(); j++) { final JSONObject singleItem = netArray.getJSONObject(j); final LinearLayout netItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item); netItemLayout.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); netItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem); netItemLayout.setGravity(Gravity.CENTER_VERTICAL); final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle); itemTitle.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f)); itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle); itemTitle.setWidth(0); itemTitle.setGravity(Gravity.LEFT); itemTitle.setText(singleItem.getString("title")); netItemLayout.addView(itemTitle); final ImageView itemClassification = new ImageView(context); itemClassification.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f)); itemClassification.setPadding(0, topBottomImg, 0, topBottomImg); itemClassification.setImageDrawable( context.getResources().getDrawable(R.drawable.traffic_lights_none)); netItemLayout.addView(itemClassification); final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue); itemValue.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f)); itemValue.setTextAppearance(context, R.style.balloonResultItemValue); itemValue.setWidth(0); itemValue.setGravity(Gravity.LEFT); itemValue.setText(singleItem.optString("value", null)); netItemLayout.addView(itemValue); netLayout.addView(netItemLayout); final View divider = new View(context); divider.setLayoutParams(new LinearLayout.LayoutParams( android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1)); divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv); divider.setBackgroundResource(R.drawable.bg_trans_light_10); netLayout.addView(divider); netLayout.invalidate(); } measurementHeader.setVisibility(View.VISIBLE); netHeader.setVisibility(View.VISIBLE); measurementLayout.setVisibility(View.VISIBLE); netLayout.setVisibility(View.VISIBLE); dateHeader.setVisibility(View.VISIBLE); resultListView.addView(resultView); Log.d(DEBUG_TAG, "View Added"); // codeText.setText(resultListItem.getString("sync_code")); } catch (final JSONException e) { e.printStackTrace(); } progessBar.setVisibility(View.GONE); emptyView.setVisibility(View.GONE); resultListView.setVisibility(View.VISIBLE); resultListView.invalidate(); } else { Log.i(DEBUG_TAG, "LEERE LISTE"); progessBar.setVisibility(View.GONE); emptyView.setVisibility(View.VISIBLE); emptyView.setText(context.getString(R.string.error_no_data)); emptyView.invalidate(); } }