【问题标题】:LinearLayout doesnt appear correctly after changing its height through applyTransformation通过 applyTransformation 更改其高度后,LinearLayout 未正确显示
【发布时间】:2013-02-01 17:23:14
【问题描述】:

我正在尝试在 LinearLayoutAnimation 上执行平滑过渡(展开/折叠)。这是我用于动画的代码:

Animation anim = new Animation(){
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t){
        super.applyTransformation(interpolatedTime, t);
        layout.getLayoutParams().height = (int)(84*interpolatedTime);
        layout.requestLayout();
    }
};

问题在于展开/折叠动画效果很好,但动画完成后布局本身并不能正确显示。下面的灰色渐变块是它的样子(而不是 textview 和 edittext):

即使我正在调用layout.requestLayout();,但它仍然不会在每个 interpolatedTime 时间刷新布局图。我这里有什么遗漏吗?

附注我在设置高度时使用 84 的原因是因为我知道我的布局的渲染高度,并且它仅在测试/调试过程中静态定义。

【问题讨论】:

    标签: android animation height android-linearlayout gradient


    【解决方案1】:

    我想我已经想通了! 关键答案是在 interpolatedTime 时间等于 1 时将视图的高度设置为 LayoutParams.WRAP_CONTENT。例如:

    if(interpolatedTime == 1)
         layout.getLayoutParams().height = LayoutParams.WRAP_CONTENT;
    else
         layout.getLayoutParams().height = (int)(84 * interpolatedTime);
    

    注意:这里 84 是我的视图高度,实际上应该使用layout.getMeasuredHeight()动态检索它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多