【发布时间】:2012-05-20 01:07:48
【问题描述】:
我有以下问题: 在我的布局 xml 中,我有一个相对布局,其中放置了一个 ImageView(可从 app /res 文件夹中绘制,已绘制)。
我需要以编程方式在与初始图像完全相同的位置添加另一个 ImageView(以及来自应用资源的另一个可绘制对象)并在其上执行动画。
我几乎成功了,使用新的可绘制对象和从初始 ImageView 获取的布局参数添加新的 ImageView,并在其上执行动画,但是初始的 ImageView(在新添加的下方)变得越来越小 - 无需调整自身大小原因(其他孩子都还好)。
如何防止这种情况发生?两张图片的宽度和高度完全相同,我需要保持相同... 提前致谢。
附:更新问题。
> <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>
现在我需要从卡片组 1 中取出一张卡片并使用动画将其放置在卡片组 2 上。 所以我做了以下事情:
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)}
所有的drawables都是相等的(宽度和高度),所以我希望不会有任何问题,但是当animatingView被添加到布局时-deck1变小,调整自身大小,它仍然是可点击和显示的但更小(并且因为它变得更小,所有其他依赖它的孩子,改变他们的位置......)
对不起,我没有使用真正的代码和xml,但现在我不在他们面前......
编辑:已解决。代码如下:
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);
【问题讨论】: