Using a png image format on android devices - android

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);

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" />

CircleImageView only support image from xml src 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.

Image stretches horizontally

I am developing an app based on client-server application. I am using tablelayout, and in tablelayout am adding some textview, edit text and image( for click ). My screenshot is as follows:
as you can see in my image add button blurs. It is just a 3kb file.
final ImageView img_add_icon = new ImageView(MainScreen.this);
img_add_icon.setBackgroundResource(R.drawable.add_item_order);
and my xml file is:
<ImageView
android:id="#+id/add_to_order_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"/>
What can I do to stop the blurring of this image?
Please Use
setImageResource(resId)
to Sets a drawable as the content of this ImageView.
To Control how the image should be resized or moved to match the size of this ImageView
use
setScaleType(ImageView.ScaleType scaleType)
[1]: http://developer.android.com/reference/android/widget/ImageView.html#setImageResource%28int%29
[2]: http://developer.android.com/reference/android/widget/ImageView.html#setScaleType%28android.widget.ImageView.ScaleType%29

Custom picture placed in Layout

Is there any way to create a custom image, and then place it into a layout you have?
Yes, you can use an ImageView.
Example xml:
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/my_image"/>
Then you would just stick my_image.png into res/drawable.
Edit - to draw dynamically you want to subclass View and override onDraw(Canvas) with a custom drawing method.
The other option is to load multiple images into res/drawable and choose between them in your Java code:
ImageView image = (ImageView) findViewById(R.id.image);
image.setBitmapResource(R.id.some_image);
Just what Matthew said. Also if you meant to place the image as the layout background you can do it like
<android:background="#drawable/background">
where "background" is an image like background.png placed in the res/drawable folder.

Categories

Resources