私は私が私の活動ではhttp://tech.chitgoks.com/2011/10/29/android-animation-to-expand-collapse-view-its-children/
で見つけたコードに基づいた以下の実行可能なソリューション、を作ってみた:
@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)のd。現在Android 2.1(APIレベル7)のデバイスをターゲットに設定しています – Cleggy