【问题标题】:Scaling a right aligned layout doesn't work as expected缩放右对齐布局无法按预期工作
【发布时间】:2013-09-13 23:04:44
【问题描述】:

我有一个带有 ImageView 的 RelativeLayout,它与屏幕右侧对齐

 android:layout_alignParentRight="true"

然后我将动画应用于布局,将其缩放到两倍大小(在 X 轴上),但由于某种原因,对齐被破坏并且布局(和其中的图像)延伸到屏幕之外正确的。我期待它向左增长,因为它与父权对齐。

我想我可以同时对 -X 应用转换,但这也有问题(1. 计算起来有点复杂,2. 使用 AnimationSet 时,fillAfter 似乎永远无法工作) .

有谁知道如何顺利​​解决这个问题? :)

【问题讨论】:

    标签: android alignment scale android-relativelayout scaleanimation


    【解决方案1】:

    显然,Android 的缩放正在做各种各样的坏事,例如它不能正确缩放 9-patch。这是一个自定义缩放动画,可以解决上述问题,并且与 9-patch 图像兼容。我还在这里获得了一些基本信息,这只是对他的解决方案的重写:How to implement expandable panels in Android?

    public class ExpandAnimation extends Animation
    {
        private final int mStartWidth;
        private final int mDeltaWidth;
        private View view;
    
        public ExpandAnimation(View view, int startWidth, int endWidth)
        {
            mStartWidth = startWidth;
            mDeltaWidth = endWidth - startWidth;
            this.view = view;
        }
    
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t)
        {
            android.view.ViewGroup.LayoutParams lp = view.getLayoutParams();
            lp.width = (int) (mStartWidth + mDeltaWidth * interpolatedTime);
            view.setLayoutParams(lp);
            view.invalidate();
        }
    
        @Override
        public boolean willChangeBounds()
        {
            return true;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 2020-02-18
      • 2012-12-20
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      相关资源
      最近更新 更多