CircleImageView only support image from xml src android - android

I am using CircleImageView for populating circle image in my android application.But after using the sample project i found that image which is circled, set from the xml using the following code:-
<com.mikhaellopez.circularimageview.CircularImageView
android:id="#+id/circleImgView"
android:layout_width="250dp"
android:layout_height="250dp"
android:src="#drawable/image"
app:border="true"
app:border_color="#color/GrayLight"
app:border_width="10"
app:shadow="true" />
After that i tried to set image to this view from java. Image is successfully set but circle effect doesn't working.
imgView = (CircularImageView)findViewById(R.id.circleImgView);
imgView.setBackgroundResource(R.drawable.image);
I need to set image programmatically using java. But it is not working by this way.

Related

how to change src attribute dynamically in android studio?

how can I set src attribute (line 7) dynamically in android studio,I tried to change the backgroundResource but is not the same
XML file
<ImageView
android:onClick="next2"
android:layout_margin="10dp"
android:id="#+id/img3"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#drawable/img3"
android:src="#9d070976"
android:layout_toEndOf="#+id/img2" />
Java code
a.setBackgroundResource(R.color.mycolor);
Depending on what form your image is in, use:
setImageBitmap()
setImageDrawable()
setImageIcon()
or setImageResource()
If your replacement image is in the form of a URL or Uri that you need to load, use an image-loading library like Picasso or Glide. They can load the image in the background and fill in the ImageView once the image is ready to be displayed.

Displaying an image from within an Android app?

I have filepath which is a String holding the absolute path to an image file.
Is there a way to display the image to the user similar to when they use the Gallery app?
When I looked up solutions to this problem, most of them involved setting an ImageView's bitmap to the bitmap decoded from the file, but I don't want to go this route because the orientations may be different, the size of the picture may not be maximized depending on how it fits within the ImageView, and so on. I basically want to have it displayed full-screen. Or if this can be done with an ImageView I'd be curious to know how.
Is this possible to do?
You can declare an ImageView in your layout that fills the parent
<ImageView
android:layout_gravity="fill"
android:id="#+id/your_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Then you use the Picasso library to load the image by
1/ Inflating the ImageView
yourImage = (ImageView) view.findViewById(R.id.your_image);
2/ Loading the image to the ImageView like
Picasso.with(context).load(filepath).fit().into(yourImage);
Check http://square.github.io/picasso/
Use the following library: TouchImageView
Usage:
Place TouchImageView.java in your project. It can then be used the same as
ImageView. Example:
TouchImageView img = (TouchImageView) findViewById(R.id.img);
If you are using TouchImageView in xml, then you must provide the full package
name, because it is a custom view. Example:
<com.example.touch.TouchImageView
android:id="#+id/img"
android:layout_width="match_parent"
android:layout_height="match_parent" />

How to parse a single png formate Image into my android Imageview from XML

I have downloaded the code from AndroidHive of customize list view but I don't want my image in list view I want to parse it from xml with a simple imageview
Assuming you already have the png image you can add that image in drawable folder
and then
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image1" />
simply refer that image with android:src of imageview
OR you can use Glide library

Using a png image format on android devices

Whenever i am using transparent PNG images, on my android device ( nexus ), i get a border on one side of transparent part. What is the way to sort out this problem ?
The image you are trying to add may not be transparent.Check it...
In the xml file, use this code to add an ImageView and set a resource for it:
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sample" />
To access the ImageView from the java code ,use the following code.
ImageView imgView = (ImageView) findViewById(R.id.image);
You can also set a resource programatically:
imgView.setImageResource(R.drawable.sample);

To align the background image to center and not stetched : in java code ANDROID (not manifest)

I'm new to android development.
I'm trying to set background to my app by using this line of code
getWindow().setBackgroundDrawableResource(R.drawable.my_imagename);
That works perfectly. But the problem is the image appears stretched. What should I do to make it align in the center (exactly like original image) and not stretched.
I would appreciate any help.
you could try to use xml layout for the background image:
<FrameLayout
android:id="#+id/fm_id"
android:layout_width="img_width"
android:layout_height="img_height"
... ...
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/my_imagename"
/>
</FrameLayout>
Hope this help
Use an ImageView to store the background and instead of setBackgroundDrawableResource() use setImageDrawable(). This sets the android:src attribute instead of the android:background attribute.
Now you can set the scale type:
android:scaleType = "centerInside";
Check the ImageView api for other scale types.
If you really need to edit the scale from java (as your question implies) you can use the setScaleType() method for ImageViews:
view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

Categories

Resources