2

我正在尝试为水平列表项设置动画,关闭 alpha 动画作品,并且 layoutparam 值也会随着时间的推移而减少,但由于某种原因,这不会改变列表项的实际高度。

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final int initialHeight = view.getMeasuredHeight();


    if(interpolatedTime == 1){

        imageAdapter.remove(view, position);


    }else{

        view.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
        view.setAlpha(1 - interpolatedTime);
        System.out.println("  v height = " + view.getHeight());
        System.out.println("  v layoutparams = " + view.getLayoutParams().height);
        view.forceLayout();
        view.invalidate();
        view.requestLayout();

    }
}

这是在 imadeAdapter 的 getView 方法中,binBtn 是您触摸以删除列表项的按钮

      binBtn.setOnTouchListener(new OnTouchListener() {


        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub


                  if (event.getAction() == MotionEvent.ACTION_UP)
                      {

                      View vp = (View) v.getParent();

                SqueezeAnimation ani = new SqueezeAnimation(this,vp,position);
                ani.setDuration(1000);
                v.startAnimation(ani);

在 Tanis 回答后更改此代码,但问题仍然相同, getHeight() 打印 674 和 getLayoutParams().height 打印 100

         else{
         RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(100, 100);

        view.setLayoutParams(lps);
        view.requestLayout();

        System.out.println("  v height = " + view.getHeight());
        System.out.println("  v layoutparams = " + view.getLayoutParams().height);

作为旁注,这是在 imageadapter 的 getView 方法中,它改变了该视图的高度,我尝试将 backgroundfillIV 传递给动画但仍然不起作用

  View backgroundfillIV =  gridView.findViewById(R.id.backroundfillbar);
       double mult =  products.get(position).value/ products.get(0).value;
       backgroundfillIV.getLayoutParams().height = (int) ( (((bottleheight+20)*0.95)/mult)); 
4

2 回答 2

7

您需要setLayoutParams()在某个时候调用以保存对 LayoutParams 的更改。

例如:

LayoutParams lps = view.getLayoutParams();
lps.height = initialHeight - (int)(initialHeight * interpolatedTime);
view.setAlpha(1 - interpolatedTime);
view.setLayoutParams(lps);

这是因为该getLayoutParams()方法仅返回 LayoutParams 引用的副本,而不是对 LayoutParams 本身的引用。在Does Java return by reference or value对此有更深入的讨论。

于 2013-07-19T13:36:39.530 回答
0

不是真正的解决方案,但问题出在我发现的 Horizo​​ntalListView 上,因为它适用于普通的列表视图

于 2013-07-19T17:16:45.597 回答