I have following problem:
in my layout xml I have relative layout in which is placed an ImageView(drawable from app /res folder, is drawn).
I need to add programmatically another ImageView(with another drawable from app resources) exactly on the same place as the initial one and to perform an animation on it.
I almost succeed ,a add new ImageView with new drawable and the layout params taken from the inital ImageView, and perform the animation on it,but the initial ImageView(which is bellow the newly added) is getting smaller – resize itself without reason(the other childs are OK).
How to prevent this?the both images are exactly the same width and height and I need to remain the same…
Thanks in advance.
P.S. update the question .
> <RelativeLayout> .... ... ... <ImageView deck1 > centerverticaly and
> leftof(other UI component) - this is the initial imageview and
> represents deck full of cards.... ... <ImageView deck2>
> centerverticaly and rightof(other UI component) - this is the second
> deck where the cards should be opened.... ... </RelativeLayout>
now I need to take a single card from deck1 and using animation to place it on deck2.
so I do the following:
if(animatingView==null){
ImageView animatingview = new ImageView(this.context);
animatingView.setImageBitmap(R.drawable.backofthecard);
animatinView.setLayoutParams(deck1.getLayoutParams);
RelativeLayout.add(animatingView);
}else{
animatingView.setVisible(visible);
}
animatingView.startAnimation(deckTranslateAnimation);
.
.
..
OnAnimationEnd{animatingView.setVisible(invisible)}
all of the drawables are equal(width and height),so I expect that there won’t be any problems ,but when the animatingView is added to a Layout – deck1 get smaller,resize itself,it is still clickable and displayed but is smaller(and because it gets smaller all the other childs that depend on it,change their places…)
Sorry I didn’t use the real code and xml,but right now I am not in front of them…
Edit:Solved.Here is the code:
if(animatingView==null){
animatingView = new ImageView(context);
animatingView.setImageResource(R.drawable.back);
RelativeLayout.LayoutParams params = new LayoutParams(animatingView.getDrawable().getMinimumWidth(), animatingView.getDrawable().getMinimumHeight());
params.addRule(RelativeLayout.ALIGN_LEFT, this.getDeckView().getCardView().getId());
params.addRule(RelativeLayout.ALIGN_TOP, this.getDeckView().getCardView().getId());
animatingView.setLayoutParams(params);
Can you show the code you are using?
Anyway, i think it is better to use FrameLayout to show views that may overlapped to each other. My first thought without seeing the code is to wrap the existing ImageView with FrameLayout. Then when you want to programmatically add new ImageView, you can do it by adding it as FrameLayout’s child. FrameLayout renders view in different layer, so the old one should not be affected when you do something with the newly added view.
[updated]
I just tried to implement placing imageview over another imageview. Anyway, I don’t seem to get the problem on the size of the overlapped image. Here are my implementation. Please try this and see if it worked or not. You may have to change some variables though.
.java
main.xml