我正在嘗試動畫水平列表項目解除 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));
感謝答案HorizontalListView,我真的認爲這將解決它,但它仍然沒有改變高度。 – Thomas
而不是獲取現有的LayoutParams,嘗試創建一組全新的LayouParams。 –
我使用了'LayoutParams lps = new LayoutParams(100,100);'並且將layoutparams更改爲100,但仍然不會更改實際尺寸。我導入了'import android.view.ViewGroup.LayoutParams;'是那個正確的,那裏有很多 – Thomas