Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以用动画隐藏Android控件吗?_Android_Animation_Android Edittext - Fatal编程技术网

我可以用动画隐藏Android控件吗?

我可以用动画隐藏Android控件吗?,android,animation,android-edittext,Android,Animation,Android Edittext,我有一个Android视图,其中包括一个带有三个单选按钮的RadioGroup。选择其中一个单选按钮时,用户还必须在EditText控件中输入文本。如果选择了其他两个单选按钮中的任何一个,则不需要此额外信息 我目前正在使用RadioGroup的OnCheckedChangedListener来确定何时选中新的单选按钮,并通过将其可见性设置为View.GONE来隐藏编辑文本。然而,这有点不和谐,我想知道是否有一种方法,我可以动画的过渡在所有。这可能吗?如果可能,那么开始的关键是什么?因为您使用的是

我有一个Android视图,其中包括一个带有三个单选按钮的RadioGroup。选择其中一个单选按钮时,用户还必须在EditText控件中输入文本。如果选择了其他两个单选按钮中的任何一个,则不需要此额外信息


我目前正在使用RadioGroup的OnCheckedChangedListener来确定何时选中新的单选按钮,并通过将其可见性设置为View.GONE来隐藏编辑文本。然而,这有点不和谐,我想知道是否有一种方法,我可以动画的过渡在所有。这可能吗?如果可能,那么开始的关键是什么?

因为您使用的是API级别7,所以答案LayoutTransition不再适用


请参阅文章:

我提出了以下可行的解决方案,它基于我在

在我的活动中:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.edit_account);
    companyGroup.setOnCheckedChangeListener(new OnCheckedChangeListener()
    {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId)
        {
            if (checkedId == R.id.companyRadio)
                EDNUtils.expandCollapse(companyNameText, true, 500);
            else
                EDNUtils.expandCollapse(companyNameText, false, 500);
        }
    });
}
EDNUtils的实施:

public static Animation expandCollapse(final View v, final boolean expand) 
{       
    return expandCollapse(v, expand, 1000);
}

public static Animation expandCollapse(final View v, final boolean expand, final int duration) 
{
    int currentHeight = v.getLayoutParams().height;
    v.measure(MeasureSpec.makeMeasureSpec(((View)v.getParent()).getMeasuredWidth(), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    final int initialHeight = v.getMeasuredHeight();

    if ((expand && currentHeight == initialHeight) || (!expand && currentHeight == 0))
        return null;

    if (expand) 
        v.getLayoutParams().height = 0;
    else 
        v.getLayoutParams().height = initialHeight;
    v.setVisibility(View.VISIBLE);

    Animation a = new Animation() 
    {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) 
        {
            int newHeight = 0;
            if (expand) 
                newHeight = (int) (initialHeight * interpolatedTime);
            else 
                newHeight = (int) (initialHeight * (1 - interpolatedTime));
            v.getLayoutParams().height = newHeight;            
            v.requestLayout();

            if (interpolatedTime == 1 && !expand)
                v.setVisibility(View.GONE);
        }

        @Override
        public boolean willChangeBounds()  
        {
            return true;
        }
    };
    a.setDuration(duration);
    v.startAnimation(a);
    return a;
}

该类仅在API级别11(Android 3.0)中引入。我目前的目标是Android 2.1(API级别7)这样的老设备