imageview

What is the difference between ImageView.setBackgroundResource and ImageView.setImageResource?

情到浓时终转凉″ 提交于 2019-11-28 08:22:45
I have seen these different approaches in setting images but I don't get the difference. Why there two methods? Dimitris Makris setBackgroundResource is for setting the background of an ImageView. setImageResource is for setting the src image of the ImageView. Given: ImageView iv = new ImageView(this); Then: iv.setBackgroundResource(R.drawable.imagedata); Will fit the image for the entire background. That means it will stretch the image to fill that background entirely even if the image size is too small. imageView.setImageResource(R.drawable.imagedata); Will occupy only the size of the image

Android: How can I stop an infinite animation applied on an ImageView?

♀尐吖头ヾ 提交于 2019-11-28 08:06:33
I have an ImageView on which I have applied a rotate animation. Since I want the rotation to go on continuously, I gave the repeatCount as infinite in my rotate.xml: android:repeatCount="infinite" In onCreate(), I load the animation and start it. Animation myAnim = AnimationUtils.loadAnimation(this, R.anim.rotate); objectImg.startAnimation(myAnim); When a button is pressed, the rotation must stop. Hence in my onClick(), I called clearAnimation(). objectImg.startAnimation(myAnim); My simple question is whether stopping the animation is the right thing to do. I assume clearAnimation()

RecyclerView: how to catch the onClick on an ImageView?

强颜欢笑 提交于 2019-11-28 07:59:20
问题 I have an ImageView in CardViews of my RecyclerView. I would like to catch the onClick on the ImageView, like I already did with the ListView. So, in the public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) I tried with: myViewHolder.imageView.setClickable(true); myViewHolder.imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.d("TEST", "Clicked"); } but this was totally ignored. The following code is working:

Android - Set ImageView to URL

允我心安 提交于 2019-11-28 07:52:58
I am trying to set an Imageview to a URL. Below is my code protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.getpic); ImageView i = (ImageView)findViewById(R.id.ivget); URL url; try { url = new URL("http://0-media-cdn.foolz.us/ffuuka/board/sp/thumb/1359/41/1359419073599s.jpg"); Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream()); i.setImageBitmap(image); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e)

Open ImageView with Zoom and Scroll

£可爱£侵袭症+ 提交于 2019-11-28 07:42:57
I would like to open an Image, in ImageView, from a button press. I need the image to be zoomable and scrollable. How would I best go about accomplishing this? Thank you! The Image can be either PNG or JPG Thank you so much! Here is my new code, you wouldn't mind skimming through and giving me a solution to all my problems with TAG , ZOOM , etc... I also know I need to add my image res to it package com.DS; import java.io.File; import android.app.Activity; import android.content.Intent; import android.graphics.Matrix; import android.graphics.PointF; import android.net.Uri; import android.os

MediaStore.Images.Media.getBitmap and out of memory error

删除回忆录丶 提交于 2019-11-28 07:38:22
My code code is: public Bitmap loadPhoto(Uri uri) { Bitmap scaled = null; try { scalled = Bitmap.createBitmap( MediaStore.Images.Media.getBitmap(getContentResolver(), uri), 0,0,90, 90); if (scaled == null) { return null; } } catch(Exception e) { } return scaled; } After this. I display scaled in ImageView. Every image comes from the device camera. Every time, I get error: out of memory after I display three photos from camera. How to solve this? Try using BitmapFactory to fix the problem http://developer.android.com/reference/android/graphics/BitmapFactory.html For those who are looking for

Load Large Image from server on Android

吃可爱长大的小学妹 提交于 2019-11-28 07:04:45
I am trying to display a jpg file from a server into an imageView. When I try to load a smaller image (300x400), there are no problems. But when I try to load a full size picture (2336x3504), the image will not load. The file size of the image is only 2mb. I do not get any errors in logcat and there are no exceptions thrown. It simply won't load the image. I also tried using this: BitmapFactory.Options options=new BitmapFactory.Options(); options.inSampleSize = 8; Bitmap preview_bitmap=BitmapFactory.decodeStream(is,null,options); This doesn't do anything to help load the large files, but it

How to insert drawables in text

扶醉桌前 提交于 2019-11-28 06:58:44
I want to insert small pictures, like arrow icons for example, into certain positions of contents of a TextView . The photo below depicts exactly what I want: Obviously, the most naive solution is to use multiple TextView on either side of the small ImageView objects. But this approach is not scalable. I am curious to learn if someone has overcome this problem with some simple yet smart trick. (Maybe with help from HTML or an external library) Any efficient solution is much appreciated. You can create SpannableString and add any object to your string TextView textView = (TextView) findViewById

Alpha-gradient on Android

房东的猫 提交于 2019-11-28 06:54:25
I need to create an alpha-gradient on the edge of the ImageView. Preferably using only XML. Image for example Here the solution the image look like below picture code for that : Prepare shape drawable res/drawable/gradient_shape.xml: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#00FFFFFF" android:endColor="#FFFFFFFF" android:type="linear" /> </shape> Define layout: activity_main.xml: <ImageView android:id="@+id/photo" android:layout_width="match_parent" android:layout_height="match_parent" android

android-TextView setText in Html.fromHtml to display image and text [duplicate]

五迷三道 提交于 2019-11-28 06:37:40
This question already has an answer here: Html.ImageGetter TextView 3 answers I try to display the text and image in Html.fromHtml() but it is doesn't work in image display. message = (TextView) findViewById (R.id.message); message.setText(Html.fromHtml( "<p><b>First, </b><br/>" + "Please press the" + "<img src = 'addbutton.png' />" + " to insert a new event.</p>")); The text are display well but the image cannot display. How can improve it? user2274349 This is the coding for reference to user pskink ... package com.tutorial.myjob; import android.app.Activity; import android.graphics.drawable