List of usage examples for android.widget ImageView setScaleType
public void setScaleType(ScaleType scaleType)
From source file:baasi.hackathon.sja.TalkActivity.java
/** * ???? ? ?/*w w w .j a va2 s. c om*/ * @param resId */ private void addToContainer(int resId) { if (containerLayout != null && containerLayout.getChildCount() <= 4) { ImageView image = new ImageView(getBaseContext()); image.setImageResource(resId); LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(170, 170); image.setLayoutParams(parms); image.setScaleType(ImageView.ScaleType.CENTER_CROP); PlayAnim(image, this, R.anim.slide_right_in, 0); image.setTag(resId); containerLayout.addView(image); } }
From source file:com.cloverstudio.spika.utils.BitmapManager.java
public void queueJob(final String url, final ImageView imageView, final ProgressBar pbLoading) { /* Create handler in UI thread. */ final Handler handler = new Handler() { @Override//from ww w . j a v a 2s .c om public void handleMessage(Message msg) { String tag = imageViews.get(imageView); if (tag != null && tag.equals(url)) { if (msg.obj != null) { if (smallImg) { imageView.setScaleType(ImageView.ScaleType.CENTER); } else { imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); } imageView.setImageBitmap((Bitmap) msg.obj); if (pbLoading != null) pbLoading.setVisibility(View.GONE); } else { // imageView.setImageBitmap(placeholder); imageView.setImageResource(R.drawable.image_stub); if (pbLoading != null) pbLoading.setVisibility(View.GONE); } } } }; pool.submit(new Runnable() { @Override public void run() { final Bitmap bmp = downloadBitmap(url); Message message = Message.obtain(); message.obj = bmp; handler.sendMessage(message); } }); }
From source file:com.ushahidi.android.app.ui.phone.AddCheckinActivity.java
@Override public View makeView() { ImageView i = new ImageView(this); i.setAdjustViewBounds(true);// w ww . j a va 2s. c o m i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutParams(new ImageSwitcher.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); return i; }
From source file:co.mrktplaces.android.ui.views.smarttablayout.SmartTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}.//from www .jav a 2 s . c o m */ protected ImageView createDefaultTabView(int resource) { ImageView imageView = new ImageView(getContext()); imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imageView.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1)); imageView.setImageResource(resource); if (tabViewBackgroundResId != NO_ID) { imageView.setBackgroundResource(tabViewBackgroundResId); } else 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); } imageView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0); if (tabViewTextMinWidth > 0) { imageView.setMinimumWidth(tabViewTextMinWidth); } return imageView; }
From source file:de.gebatzens.ggvertretungsplan.fragment.MensaFragment.java
private CardView createCardItem(Mensa.MensaItem mensa_item, LayoutInflater i) { CardView mcv = createCardView();/*from w w w .j a v a 2 s . com*/ mcv.setContentPadding(0, 0, 0, 0); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.setMargins(0, 0, 0, toPixels(6)); mcv.setLayoutParams(params); i.inflate(R.layout.mensa_cardview_entry, mcv, true); if (mensa_item.isPast()) mcv.setAlpha(0.65f); String[] colors = getActivity().getResources().getStringArray(GGApp.GG_APP.provider.getColorArray()); ((TextView) mcv.findViewById(R.id.mcv_date)).setText(getFormatedDate(mensa_item.date)); ((TextView) mcv.findViewById(R.id.mcv_meal)).setText(mensa_item.meal); ((TextView) mcv.findViewById(R.id.mcv_garnish)).setText(getResources().getString(R.string.garnish) + ": " + mensa_item.garnish.replace("mit ", "").replace("mit", "")); ((TextView) mcv.findViewById(R.id.mcv_day)).setText(getDayByDate(mensa_item.date)); ((ImageView) mcv.findViewById(R.id.mcv_imgvegi)).setImageBitmap((Integer.valueOf(mensa_item.vegi) == 1) ? BitmapFactory.decodeResource(getResources(), R.drawable.vegi) : BitmapFactory.decodeResource(getResources(), R.drawable.meat)); if (screen_orientation_horizotal) { LinearLayout mcvImageContainer = (LinearLayout) mcv.findViewById(R.id.mcv_image_container); ViewGroup.LayoutParams mcvImageContainerLayoutParams = mcvImageContainer.getLayoutParams(); mcvImageContainerLayoutParams.height = toPixels(240); } ViewHolder vh = new ViewHolder(); vh.imgview = (ImageView) mcv.findViewById(R.id.mcv_image); vh.filename = mensa_item.image; new AsyncTask<ViewHolder, Void, ViewHolder>() { @Override protected ViewHolder doInBackground(ViewHolder... params) { //params[0].bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.block_house_steak); try { Bitmap bitmap; if (cacheCheckDir()) { bitmap = cacheGetBitmap(params[0].filename); if (bitmap != null) { params[0].bitmap = bitmap; } else { bitmap = GGApp.GG_APP.provider.getMensaImage(params[0].filename); cacheSetBitmap(params[0].filename, bitmap); params[0].bitmap = bitmap; } } else { bitmap = GGApp.GG_APP.provider.getMensaImage(params[0].filename); cacheSetBitmap(params[0].filename, bitmap); params[0].bitmap = bitmap; } } catch (IOException e) { e.printStackTrace(); params[0].bitmap = null; } return params[0]; } @Override protected void onPostExecute(ViewHolder result) { try { ImageView imgView = (ImageView) result.imgview; if (result.bitmap != null) { imgView.setImageBitmap((Bitmap) result.bitmap); } else { imgView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.no_content)); } imgView.setScaleType(ImageView.ScaleType.CENTER_CROP); } catch (Exception e) { e.printStackTrace(); } } }.execute(vh); return mcv; }
From source file:prince.app.sphotos.tools.ActivityX.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) protected void initDrawerView() { mDrawerLayout = (DrawerLayout) findViewById(getDrawerLayoutId()); mDrawerList = (ListView) findViewById(getDrawerListId()); mDrawerList.setFastScrollEnabled(true); //set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); ImageView bigPhoto = (ImageView) findViewById(getBigPhotoId()); ImageView smallPhoto = (ImageView) findViewById(getSmallPhotoId()); /* bigPhoto.setLayoutParams(new RelativeLayout.LayoutParams( getResources().getDimensionPixelSize(R.dimen.drawer_photo_width), getResources().getDimensionPixelSize(R.dimen.drawer_photo_width))); */ bigPhoto.setScaleType(ImageView.ScaleType.CENTER_CROP); /* smallPhoto.setLayoutParams(new RelativeLayout.LayoutParams( getResources().getDimensionPixelSize(R.dimen.user_drawer_photo_width), getResources().getDimensionPixelSize(R.dimen.user_drawer_photo_width)));*/ smallPhoto.setScaleType(ImageView.ScaleType.CENTER_CROP); bigPhoto.setImageBitmap(getBigPhoto()); smallPhoto.setImageBitmap(getSmallPhoto()); String[] social = getResources().getStringArray(R.array.social_accounts); //Set the adapter for the list view mAccounts = new ArrayList<Account>(); for (int i = 0; i < social.length; i++) { Account item = new Account(socialIcons[i], social[i]); mAccounts.add(item);// w w w. ja va 2 s . c o m } // set the ListViewAdapter mDrawerList.setAdapter(new ListViewListener(this, R.layout.social_media_accounts, mAccounts)); //Set the list's click listener mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); //enable ActionBar app icon to behave as action to toggle nav drawer mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerOpened(View view) { getActionBar().setTitle("Accounts"); } public void onDrawerClosed(View view) { getActionBar().setTitle(getBarTitle()); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); }
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 w w. j a v a2 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:org.alfresco.mobile.android.application.fragments.workflow.task.TaskDetailsFragment.java
private void diplayAttachment() { vRoot.findViewById(R.id.attachments_waiting).setVisibility(View.GONE); LinearLayout ll = (LinearLayout) vRoot.findViewById(R.id.attachments); if (items == null || items.isEmpty()) { ImageView iv = new ImageView(getActivity()); iv.setScaleType(ScaleType.FIT_CENTER); iv.setImageResource(R.drawable.mime_empty_doc); ll.addView(iv, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); TextView tv = new TextView(getActivity()); tv.setText(R.string.process_no_attachments); tv.setGravity(Gravity.CENTER);/*from w ww .ja v a 2s. c o m*/ ll.addView(tv, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); ll.setGravity(Gravity.CENTER); return; } LayoutInflater li = LayoutInflater.from(getActivity()); View vr = null; TextView tv = null; for (Node node : items) { vr = li.inflate(R.layout.app_task_item_row, ll, false); tv = (TextView) vr.findViewById(R.id.toptext); tv.setText(node.getName()); tv = (TextView) vr.findViewById(R.id.bottomtext); tv.setText(createContentBottomText(getActivity(), node)); ll.addView(vr, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); ImageView iv = (ImageView) vr.findViewById(R.id.icon); RenditionManager.with(getActivity()).loadNode(node) .placeHolder(MimeTypeManager.getInstance(getActivity()).getIcon(node.getName(), true)).into(iv); vr.setTag(node); vr.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Node item = (Node) v.getTag(); NodeDetailsFragment.with(getActivity()).nodeId(item.getIdentifier()).back(true).display(); } }); } }
From source file:com.cc.custom.uikit.PagerSlidingTabStrip.java
private void addIconTab(final int position, int resId) { ImageView tab = new ImageView(getContext()); tab.setImageResource(resId);// w ww . jav a 2 s. com tab.setScaleType(ImageView.ScaleType.CENTER_INSIDE); addTab(position, tab); }
From source file:kr.wdream.ui.Components.PagerSlidingTabStrip.java
private void addIconTab(final int position, int resId) { ImageView tab = new ImageView(getContext()) { @Override/*w ww . ja va2 s . c om*/ protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (pager.getAdapter() instanceof IconTabProvider) { ((IconTabProvider) pager.getAdapter()).customOnDraw(canvas, position); } } }; tab.setFocusable(true); tab.setImageResource(resId); tab.setScaleType(ImageView.ScaleType.CENTER); tab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pager.setCurrentItem(position); } }); tabsContainer.addView(tab); tab.setSelected(position == currentPosition); }