Animated dialog with AsyncTask - android

I need to draw a custom(Animation of Image) dialog with AsyncTask. I created a layout with TextView and ImageView to display message and play animation of the images.
Please let me know how can I update the image of the ImageView object to display animation.
Thanks,
Android_IT

Hm, in my project, I show preview of camera like this:
ImageView imagePreview = (ImageView) layout.findViewById(R.id.previewImage);
imagePreview.setImageBitmap(selectedBitmap);

Related

Set an image in imageView

I'm pretty new in Android and I am trying to make a Mancala (it's kind of an African game) app. I am looking for a way to update an Image View from one image to another programmatically (for those who are familiar with the game- I want the images of the empty holes to update to images with balls every time the player plays).
I tried to look for an answer but I didn't find one. Here is what I've tried:
imgHome2=(ImageView)findViewById(R.drawable.home0);
You can do same by using Drawable:
private ImageView imageView;
on onCreate()
imageView = (ImageView) findViewById(imageView);
Create new method for set drawable on ImageView.
private void setDrawableOnImageView(Drawable drawable){
imageView.setImageDrawable(drawable);
}
How to call above method:
Drawable drawable = getResources().getDrawable(R.drawable.ic_launcher);
setDrawableOnImageView(drawable);
You can change drawable as your requirement.
in findViewById you should pass an id not a drawable
imgHome2=(ImageView)findViewById(R.id.myimageviewid)
and than you can change the image by
imgHome2.setBackground(R.drawable.home0);

Removing image from ImageView and load new Image

I am facing problem on removing image from ImageView.
What I want an Image is loaded in ImageView, and then a new Image is taken by the camera and now that Image should load in ImageView replacing the previous one. I have tried
invalidate();
setImageBitmap(null);
setImageResource(0);
All these 3 methods are not working. Can someone help me.
Use this for setting image in ImageView
image.setImageResource(R.drawable.image);
If you want to set the Image By Drawable Image you can use like this
your_image_view.setImageDrawable(context.getResources().getDrawable(your_drawable_Image_id));
If you want to set the image by BitMapDrawable
your_image_view.setBackgroundDrawable(your_drawable_bitmap);
edit_countflag.setBackgroundColor(0);
edit_countflag.setImageResource(R.drawable.flag_id);

Android: Placing a bitmap or drawable image into an XML displayed screen

Well after days of looking I come to the source.
I have main screen that is drawn and created in Eclipse Graphical layout.
It consists of buttons across the top of the screen. Below the buttons is image.png area.
On startup of app it displays correctly. Buttons at top and graphic image below the buttons.
On pushing each button I want the image to be changed. I can supply either a drawable or bitmap image (figured that out).
I need help. What I don't understand is how I get an external image to display with the XML generate screen buttons.
I have currently many test trials but none give me what I am looking for.
I want to place either a drawable or bitmap image into R.id.imgVwMain and have it display with the buttons. I know I've got extra code in what is provided.
R.id.imgVwMain as a default has an image in it at start up (ie splash screen) but I want to replace it dynamically on button push.
Code snippets:
ImageView img=new ImageView(this);
View image;
Drawable drawable= getImg(0); // GETS NEW IMAGE as drawable
img.setImageDrawable(drawable);
//setContentView(img); // when uncommented displays just the image no buttons, not what needed
//R.id.imgVwMain // the target ID to place the new image into
image = findViewById(R.id.imgVwMain);
ImageView imageView=(ImageView)findViewById(R.id.imgVwMain);
imageView.setImageBitmap(drawableToBitmap(drawable));
image.setImageResource(imageView);
setContentView(R.layout.main); //of course this just displays default of the XML
Set onClickListeners onto your buttons like so:
Button mButton = (Button) findViewById(R.id.my_button);
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ImageView ivImage = (ImageView) findViewById(R.id.imgVwMain);
ivImage.setImageDrawable(getImg(0));
}
});
Now, whenever the button is clicked it set's the image of your imageview to whatever you'd like.
You can probably use addView to add an imageView dynamically and likewise call removeView to get rid of an imageView. At some point you'll need to set the layout parameters as well. Hopefully this will get you started:
myParentViewOrLayout.removeView(oldImage);
ImageView newImage = (ImageView) findViewById(R.id.imgToAdd);
//Set your layoutParams
myParentViewOrLayout.addView(newImage);

How to center a Imageview on the screen? (with java code)

atm i'm using this code, but this code doesn't works for me, because the code is stretching the Image on the screen, i dont want that, i need that the image uses his real size (200x210)
FrameLayout fl = new FrameLayout(this.getApplicationContext());
splash = new ImageView(getApplicationContext());
splash.setImageResource(R.drawable.logo2);
fl.addView(splash);
fl.setForegroundGravity(Gravity.CENTER);
fl.setBackgroundColor(Color.BLACK);
setContentView(fl);
How to do it without making a giant image that it is using all the screen?
You have to specify scalType if you don't want imageview to stretch your image.
splash.setScaleType(ScaleType.CENTER);
use this properties of ImageView as shown here:
splash.setAdjustViewBounds(true);
and tell me if it is working.

Getting imageview to read image from sd

I have a imageview and a camera button in Activity A. By clicking on the camera button will go to my custom camera activity. After taking a picture and storing it into a folder, how can I reflect this newly picture taken in the imageview after finishing the camera activity? Any help will be appreciated ?
A(main) > B(camera activity) > A(main) Imageview is updated with new picture taken.
Thanks.
According to my understanding of your question, you want to know how to set an image, residing on sdCard, to an ImageView. Well, let's say you can get the image path from your camera activity and then you can do something like below:
String imageInSD = "/sdcard/img.PNG";
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
ImageView myImageView = (ImageView)findViewById(R.id.imageview);
myImageView.setImageBitmap(bitmap);
I hope it'll serve the purpose, if this is what you want.

Categories

Resources