Multiple images in image flipper Android - android

I'm using this code to dynamically pop images on the slider using Image Flipper.
flipper= (ViewFlipper) findViewById(R.id.flipper1);
for(int i=0;i<6;i++)
{
// This will create dynamic image view and add them to ViewFlipper
Button image = new Button(getApplicationContext());
image.setBackgroundResource(R.drawable.stock_bg);
image.setText("Sps"+i);
// image.getLayoutParams().height=40;
// image.getLayoutParams().width=40;
flipper.addView(image);
}
I have set sliding animation to it. The issue is that it fits one image on the whole screen width and then animates to other. While I want the image size to remain same and it should not fit it to the entire screen. Also note that if I change the flipper width from wrap content to custom width, it will not slide the entire screen. Putting it simple, how can I force the flipper to show more then 1 image on the screen at a time.

Related

Change imageview backgrounds on drop

I have created a drag and drop application that allows the user to drag 4 images from the top and put them in order at the bottom. I have 4 image views on top and 4 imageviews on the bottom. Bringing them down works perfectly, however when I attempt to move them side to side I run into problems.
I have 2 temporary imageviews where I set them equal to a imageview. If i move an image from image view 6 to image view 5, it is supposed to swap the images, but it just changes image view 6 to what image view 5 was and image view 5 stays the same.
Here is the code snippet to where I am attempting to change the images
droppedSwap is equal to the image the user chose to move
dropTargetSwap is equal to where the user wants the image to go
if (dropTargetSwap.equals(ivHero5) && droppedSwap.equals(ivHero6))
{
//set temp imageview that is equal to ivHero5
ImageView tempDropTarget = ivHero5;
//set temp imageview that is equal to ivHero6
ImageView tempDropped = ivHero6;
//supposed to set ivHero6 to ivHero5 image
droppedSwap.setBackground(tempDropTarget.getBackground());// working
//supposed to set ivHero5 to ivHero6 image
dropTargetSwap.setBackground(tempDropped.getBackground());// not working
}
You're problem is that by doing:
ImageView tempDropTarget = ivHero5;
ImageView tempDropped = ivHero6;
You're not actually creating temporary copies but rather references to the original objects, so when you do droppedSwap.setBackground() you're actually setting the ivHero6 background and when you do tempDropped.getBackground() you're getting the ivHero6 background that was changed earlier.
You should create a copy of the backgrounds, which are drawables using:
Drawable copy1 = ivHero5.getBackground().getConstantState().newDrawable();
Drawable copy2 = ivHero6.getBackground().getConstantState().newDrawable();

How to position a View in Android to match space in background

I have a layout where I have to take an ImageView, and position it somewhere relative to something in the background image. For instance, the ImageView would be of an item, and on the background image there would be a shelf, and I would need to position the ImageView such that the item looks like it is on the shelf. Another example would be of a frame in the background, and I would need to position the image so it looks like it is in the frame. This needs to account for scaling. I do not need it to work through rotation, as there are different layouts for portrait and landscape.
One way would be to associate the relative position of these items with the background images themselves. For instance, the height of the position of the top of the table is at x% of the total height of the image. Then, when it scales, it's now at x% of the current height.

Android: Repositioning ImageView

i have 2 imageview. first one for containing the image and the other one as the frame.
i already set image position to have the same position as the frame after loading the image.
i also already check the value and its the same.
but somehow the image position is not the same as the frame when i try changing picture with 2 different size (width x height).
ivProfilePicture.setX(ivFrame.getX());
ivProfilePicture.setY(ivFrame.getY());
by the way, i use custom imageview for the image container, i only custom the function onMeasure. there's no image repositioning.

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 position a view off-screen so that it can be Animated to move on-screen?

I have a RelativeLayout filling the screen and a couple of ImageView positioned on it using LayoutParams margins. These ImageView are animated in different ways, and in one case I want an image to "fly in" to the screen from the right.
Unfortunately, if I set leftMargin for that ImageView greater than the width of the screen, it does not appear (or appears cropped if it partially visible at the start of animation).
I tried setting width and height of RelativeLayout to be bigger than screen size - it works, but only partially: if the image is positioned completely off-screen, it does not work, and if the image is partially visible, it is not cropped, but that works only for right and bottom sides.
So, my question is this: how to position several ImageViews on and off the screen so that I can animate them using Animation?
In the end, I used a trick: I combined AnimationDrawable and view animation. I did the following (assuming that the animation has to run T milliseconds):
Position that ImageView on-screen.
Set as its background an AnimationDrawable with following frames:
empty Drawable: 1ms,
normal Drawable: Tms.
Change view's animation to this:
jump to off-screen position (translation with duration=1ms),
do normal animation.
This is probably a good place to start looking for those who would use Fixpoint's solution.
Android — How to position View off-screen?

Categories

Resources