List of usage examples for android.widget ImageView requestLayout
@CallSuper public void requestLayout()
From source file:Main.java
/** * Resize ImageView//from w ww .j a v a 2s . c o m * @param iv */ public static void resizeImageView(ImageView iv, int w, int h) { if (iv != null && w > 0 && h > 0) { iv.requestLayout(); iv.getLayoutParams().width = w; iv.getLayoutParams().height = h; } }
From source file:Main.java
static public void setImageViewSize(ImageView imageView) { ViewGroup.LayoutParams params = imageView.getLayoutParams(); params.height = 250;//from w w w.j a v a 2s . c om imageView.setLayoutParams(params); imageView.requestLayout(); }
From source file:Main.java
/** * Sets the image for an ImageView.//from w ww . java 2s . c o m */ public static void setImage(ImageView view, Drawable drawable) { view.setImageDrawable(drawable); if (drawable != null) { view.setAdjustViewBounds(true); } view.requestLayout(); }
From source file:Main.java
static public void setImageViewSizeMax(ImageView imageView, int width, int height) { ViewGroup.LayoutParams params = imageView.getLayoutParams(); params.height = height;//from w w w . ja v a 2 s .c o m params.width = width; imageView.setLayoutParams(params); imageView.requestLayout(); }
From source file:me.albinmathew.celluloid.ui.fragments.MovieDetailFragment.java
public void showTrailers(@NonNull List<VideoResponseBean> trailers) { if (trailers.isEmpty()) { mTrailerLabel.setVisibility(View.GONE); mTrailersView.setVisibility(View.GONE); mTrailersScrollView.setVisibility(View.GONE); } else {/*from www .j a va 2s .c o m*/ mTrailerLabel.setVisibility(View.VISIBLE); mTrailersView.setVisibility(View.VISIBLE); mTrailersScrollView.setVisibility(View.VISIBLE); mTrailersView.removeAllViews(); if (mContext != null && isAdded()) { LayoutInflater inflater = getActivity().getLayoutInflater(); Picasso picasso = Picasso.with(getContext()); shareVideos(); for (VideoResponseBean trailer : trailers) { ViewGroup thumbContainer = (ViewGroup) inflater.inflate(R.layout.video, mTrailersView, false); ImageView thumbView = (ImageView) thumbContainer.findViewById(R.id.video_thumb); thumbView.setTag(CommonUtil.getUrl(trailer)); thumbView.requestLayout(); thumbView.setOnClickListener(this); picasso.load(CommonUtil.getThumbnailUrl(trailer)) .resizeDimen(R.dimen.video_width, R.dimen.video_height).centerCrop() .placeholder(R.color.cardview_shadow_start_color).into(thumbView); mTrailersView.addView(thumbContainer); } } } }
From source file:com.dm.wallpaper.board.adapters.LatestAdapter.java
private void resetImageViewHeight(@NonNull ImageView imageView, ImageSize imageSize) { if (imageSize == null) imageSize = new ImageSize(400, 300); int width = WindowHelper.getScreenSize(mContext).x; int spanCount = mContext.getResources().getInteger(R.integer.latest_wallpapers_column_count); if (spanCount > 1) { width = width / spanCount;//from ww w . j a v a 2s . co m } double scaleFactor = (double) width / (double) imageSize.getWidth(); double measuredHeight = (double) imageSize.getHeight() * scaleFactor; imageView.getLayoutParams().height = Double.valueOf(measuredHeight).intValue(); imageView.requestLayout(); }
From source file:com.asksven.betterbatterystats.adapters.StatsAdapter.java
public View getView(int position, View convertView, ViewGroup viewGroup) { StatElement entry = m_listData.get(position); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.m_context); boolean bShowBars = sharedPrefs.getBoolean("show_gauge", false); if (LogSettings.DEBUG) { Log.i(TAG, "Values: " + entry.getVals()); }/*from ww w .j av a2 s . c o m*/ if (convertView == null) { LayoutInflater inflater = (LayoutInflater) m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // depending on settings show new pie gauge or old bar gauge if (!bShowBars) { convertView = inflater.inflate(R.layout.stat_row, null); } else { convertView = inflater.inflate(R.layout.stat_row_gauge, null); } } final float scale = this.m_context.getResources().getDisplayMetrics().density; TextView tvName = (TextView) convertView.findViewById(R.id.TextViewName); ///////////////////////////////////////// // we do some stuff here to handle settings about font size and thumbnail size String fontSize = sharedPrefs.getString("medium_font_size", "16"); int mediumFontSize = Integer.parseInt(fontSize); //we need to change "since" fontsize tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, mediumFontSize); // We need to handle an exception here: Sensors do not have a name so we use the fqn instead if (entry instanceof SensorUsage) { tvName.setText(entry.getFqn(UidNameResolver.getInstance(m_context))); } else { tvName.setText(entry.getName()); } boolean bShowKb = sharedPrefs.getBoolean("enable_kb", true); ImageView iconKb = (ImageView) convertView.findViewById(R.id.imageKB); iconKb.setVisibility(View.INVISIBLE); TextView tvFqn = (TextView) convertView.findViewById(R.id.TextViewFqn); tvFqn.setText(entry.getFqn(UidNameResolver.getInstance(m_context))); TextView tvData = (TextView) convertView.findViewById(R.id.TextViewData); // for alarms the values is wakeups per hour so we need to take the time as reference for the text if (entry instanceof Alarm) { tvData.setText(entry.getData((long) m_timeSince)); } else { tvData.setText(entry.getData((long) m_maxValue)); } //LinearLayout myLayout = (LinearLayout) convertView.findViewById(R.id.LinearLayoutBar); LinearLayout myFqnLayout = (LinearLayout) convertView.findViewById(R.id.LinearLayoutFqn); LinearLayout myRow = (LinearLayout) convertView.findViewById(R.id.LinearLayoutEntry); // long press for "copy to clipboard" convertView.setOnLongClickListener(new OnItemLongClickListener(position)); if (!bShowBars) { GraphablePie gauge = (GraphablePie) convertView.findViewById(R.id.Gauge); ///////////////////////////////////////// // we do some stuff here to handle settings about font size and thumbnail size String iconDim = sharedPrefs.getString("thumbnail_size", "56"); int iconSize = Integer.parseInt(iconDim); int pixels = (int) (iconSize * scale + 0.5f); //we need to change "since" fontsize gauge.getLayoutParams().height = pixels; gauge.getLayoutParams().width = pixels; gauge.requestLayout(); //////////////////////////////////////////////////////////////////////////////////// if (entry instanceof NetworkUsage) { gauge.setValue(entry.getValues()[0], ((NetworkUsage) entry).getTotal()); } else { double max = m_maxValue; // avoid rounding errors leading to values > 100 % if (entry.getValues()[0] > max) { max = entry.getValues()[0]; Log.i(TAG, "Upping gauge max to " + max); } gauge.setValue(entry.getValues()[0], max); } } else { GraphableBars buttonBar = (GraphableBars) convertView.findViewById(R.id.ButtonBar); int iHeight = 10; try { iHeight = Integer.valueOf(sharedPrefs.getString("graph_bar_height", "10")); } catch (Exception e) { iHeight = 10; } if (iHeight == 0) { iHeight = 10; } buttonBar.setMinimumHeight(iHeight); buttonBar.setName(entry.getName()); buttonBar.setValues(entry.getValues(), m_maxValue); } ImageView iconView = (ImageView) convertView.findViewById(R.id.icon); LinearLayout iconLayout = (LinearLayout) convertView.findViewById(R.id.LayoutIcon); ///////////////////////////////////////// // we do some stuff here to handle settings about font size and thumbnail size String iconDim = sharedPrefs.getString("thumbnail_size", "56"); int iconSize = Integer.parseInt(iconDim); int pixels = (int) (iconSize * scale + 0.5f); //we need to change "since" fontsize iconView.getLayoutParams().width = pixels; iconView.getLayoutParams().height = pixels; iconView.requestLayout(); //n 20;setLay.setTextSize(TypedValue.COMPLEX_UNIT_DIP, iconSize); //////////////////////////////////////////////////////////////////////////////////// // add on click listener for the icon only if KB is enabled // if (bShowKb) // { // // set a click listener for the list // iconKb.setOnClickListener(new OnIconClickListener(position)); // } // show / hide fqn text if ((entry instanceof Process) || (entry instanceof State) || (entry instanceof Misc) || (entry instanceof NativeKernelWakelock) || (entry instanceof Alarm) || (entry instanceof SensorUsage)) { myFqnLayout.setVisibility(View.GONE); } else { myFqnLayout.setVisibility(View.VISIBLE); } // show / hide package icons (we show / hide the whole layout as it contains a margin that must be hidded as well if ((entry instanceof NativeKernelWakelock) || (entry instanceof State) || (entry instanceof Misc)) { iconView.setVisibility(View.GONE); } else { iconView.setVisibility(View.VISIBLE); iconView.setImageDrawable(entry.getIcon(UidNameResolver.getInstance(m_context))); // set a click listener for the list iconView.setOnClickListener(new OnPackageClickListener(position)); } // add on click listener for the list entry if details are availble if ((entry instanceof Alarm) || (entry instanceof NativeKernelWakelock) || (entry instanceof SensorUsage)) { convertView.setOnClickListener(new OnItemClickListener(position)); } // // show / hide set dividers // ListView myList = (ListView) convertView.getListView(); //findViewById(R.id.id.list); // myList.setDivider(new ColorDrawable(0x99F10529)); // myList.setDividerHeight(1); return convertView; }
From source file:tk.melnichuk.kommunalchik.CustomViews.SlidingTabLayout.java
private void populateTabStrip() { PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;/*from w w w .ja va 2 s.co m*/ TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(R.layout.bills_menu_icon, mTabStrip, false); int mipmapResName = ((BillsFragment.BillsPagerAdapter) adapter).getMipMapResourceName(i); ImageView imageView = (ImageView) tabView; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); imageView.setBackgroundResource(outValue.resourceId); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); imageView.setPadding(2 * padding, padding, 2 * padding, padding); ; // imageView.setLayoutParams(mTabStrip.getLayoutParams()); imageView.setImageResource(mipmapResName); tabView.setOnClickListener(tabClickListener); mTabStrip.addView(imageView); imageView.requestLayout(); continue; } // if (tabView == null) { // tabView = createDefaultTabView(getContext()); // } // if (tabTitleView == null && TextView.class.isInstance(tabView)) { // tabTitleView = (TextView) tabView; // } // tabTitleView.setText(adapter.getPageTitle(i)); // tabView.setOnClickListener(tabClickListener); // mTabStrip.addView(tabView); } }
From source file:com.android.contacts.list.MultiSelectContactsListFragment.java
/** * Show account icon, count of contacts and account name in the header of the list. *///from www .j av a 2 s . c o m protected void bindListHeader(Context context, View listView, View accountFilterContainer, AccountWithDataSet accountWithDataSet, int memberCount) { if (memberCount < 0) { hideHeaderAndAddPadding(context, listView, accountFilterContainer); return; } bindListHeaderCommon(listView, accountFilterContainer); final AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(context); final AccountType accountType = accountTypeManager.getAccountType(accountWithDataSet.type, accountWithDataSet.dataSet); // Set text of count of contacts and account name final TextView accountFilterHeader = (TextView) accountFilterContainer .findViewById(R.id.account_filter_header); final String headerText = shouldShowAccountName(accountType) ? String.format(context.getResources().getQuantityString(R.plurals.contacts_count_with_account, memberCount), memberCount, accountWithDataSet.name) : context.getResources().getQuantityString(R.plurals.contacts_count, memberCount, memberCount); accountFilterHeader.setText(headerText); accountFilterHeader.setAllCaps(false); // Set icon of the account final Drawable icon = accountType != null ? accountType.getDisplayIcon(context) : null; final ImageView accountFilterHeaderIcon = (ImageView) accountFilterContainer .findViewById(R.id.account_filter_icon); // If it's a writable Google account, we set icon size as 24dp; otherwise, we set it as // 20dp. And we need to change margin accordingly. This is because the Google icon looks // smaller when the icons are of the same size. if (accountType instanceof GoogleAccountType) { accountFilterHeaderIcon.getLayoutParams().height = getResources() .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_size); accountFilterHeaderIcon.getLayoutParams().width = getResources() .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_size); setMargins(accountFilterHeaderIcon, getResources().getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_left_margin), getResources().getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_right_margin)); } else { accountFilterHeaderIcon.getLayoutParams().height = getResources() .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_size_alt); accountFilterHeaderIcon.getLayoutParams().width = getResources() .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_size_alt); setMargins(accountFilterHeaderIcon, getResources() .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_left_margin_alt), getResources() .getDimensionPixelOffset(R.dimen.contact_browser_list_header_icon_right_margin_alt)); } accountFilterHeaderIcon.requestLayout(); accountFilterHeaderIcon.setVisibility(View.VISIBLE); accountFilterHeaderIcon.setImageDrawable(icon); }