【问题标题】:how to fit RelativeLayout after a Scale Animation缩放动画后如何适应RelativeLayout
【发布时间】:2015-04-10 10:11:02
【问题描述】:

将此动画应用到我的(子)RelativeLayout 后,我​​的背景图像具有良好的尺寸,但我的布局似乎继续在我的页面(父)RelativeLayout 上占据很多位置。有什么想法吗?

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:toXScale="0.2"
    android:toYScale="0.2"
    android:duration="700"
    >
</scale>
</set>

<RelativeLayout ...>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/chieldLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/bigImage"
    >
    <Button
        style="@style/boutonBrun"
        android:id="@+id/btPanier"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/full22lightgreen"

        />

</RelativeLayout>

</RelativeLayout>

我已经添加了,就像你建议我使用这个命令来适应我的布局:

params.width = (int)  getResources().getDimension(R.dimen.size_width);

我怎么知道我必须输入的“size_width”?就像我要求从 1.0 缩放到 0.2 并最终放入 android:layout_width="300dp",我想象“size_width”必须占用 60dp (300 * 0.2) 但与动画后的尺寸相比它非常小。

【问题讨论】:

    标签: android scale android-relativelayout


    【解决方案1】:

    像这样使用动画监听器

        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
    
            }
    
            @Override
            public void onAnimationEnd(Animation animation) {
                // set height for your relative layout here
            }
    
            @Override
            public void onAnimationRepeat(Animation animation) {
    
            }
        });
    

    【讨论】:

      【解决方案2】:

      我不确定我是否正确理解了您的问题,但您可以在动画中添加动画侦听器:

      yourAnimation.setAnimationListener(new Animation.AnimationListener() {
                           @Override
                           public void onAnimationStart(Animation animation) {
      
                           }
      
                           @Override
                           public void onAnimationEnd(Animation animation) {
      
                           }
      
                           @Override
                           public void onAnimationRepeat(Animation animation) {
      
                           }
                        });
      

      并在 onAnimationEnd 尝试使您的视图无效。

      yourView.invalidate();
      

      【讨论】:

      • 问题是当我将缩放动画应用到我的布局时,他只是正确地改变了背景(对我来说它是一个图像),但布局本身似乎没有正确地改变大小(我知道因为其他元素通过 android:layout_alignBottom="id..." 附加到他身上,不要移动)。因此,当我尝试适应监听器 onAnimationEnd() 时,布局似乎采用了合适的尺寸,但在这种情况下,他的背景(图像)之后太小了。恢复:我的缩放动画不会改变布局本身的大小,而只会改变他的背景。谢谢你的时间:-)
      【解决方案3】:

      最后,我只是停止使用参数android:fillAfter =“true”,他似乎没有改变布局的大小......我只是用onAnimationEnd改变了我的布局大小。

        RelativeLayout.LayoutParams  params = (RelativeLayout.LayoutParams) myRelativeLayout.getLayoutParams();
      
        params.width = (int) getResources().getDimension(R.dimen.little_house_width);
        params.height = (int) getResources().getDimension(R.dimen.little_house_height);
        setLayoutParams(params);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-15
        • 2015-09-15
        • 1970-01-01
        相关资源
        最近更新 更多