2013-07-19 103 views
1

我正在嘗試動畫水平列表項目解除 alpha動畫作品和layoutparam值也隨時間減少 但由於某些原因,不會更改列表項目的實際高度。layoutParams not changing

@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); 

改變這種代碼坦尼斯的回答後,但仍同樣的問題, 按鈕所述的getHeight()打印674和getLayoutParams()。高度打印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); 

作爲一個方面說明這是的getView方法在imageadapter以及改變這種觀點的高度,我用盡傳入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)); 

回答

5

你需要調用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上有更深入的討論。

+0

感謝答案Horizo​​ntalListView,我真的認爲這將解決它,但它仍然沒有改變高度。 – Thomas

+0

而不是獲取現有的LayoutParams,嘗試創建一組全新的LayouParams。 –

+0

我使用了'LayoutParams lps = new LayoutParams(100,100);'並且將layoutparams更改爲100,但仍然不會更改實際尺寸。我導入了'import android.view.ViewGroup.LayoutParams;'是那個正確的,那裏有很多 – Thomas

0

不是一個真正的解決方案,但問題是,我發現,因爲它爲一個正常的列表視圖