Вот как я это сделал в пользовательском представлении, которое я создал.У меня было представление, которое я хотел отобразить, уже закодированное в файл макета xml с android:visibility = "gone"
.Единственное, что я еще не понял, - это когда масштабируемое поле EditText увеличивает текст, а затем уменьшает его до нормального размера.Если я найду решение этой проблемы, я опубликую его.
private EditText m_editText;
protected void onFinishInflate ()
{
super.onFinishInflate ();
m_editText = (EditText) findViewById(R.id.edit_text);
}
public void displayView(View activateView)
{
if (activateView.getVisibility() == View.GONE)
{
//fade in from top
activateView.setVisibility(View.VISIBLE);
final Animation fadeInFromTopAnimation = AnimationUtils.loadAnimation(context, R.anim.fade_in_from_top);
fadeInFromTopAnimation.setAnimationListener(new AnimationListener()
{
public void onAnimationStart(Animation anim)
{
//Shrink the text box down while inserting new view
//Add any padding or margins if needed
float scale = (float)(m_editText.getHeight() + m_weatherRow.getHeight()) / m_editText.getHeight();
AnimationSet shrinkDownAnimation = new AnimationSet(true);
shrinkDownAnimation.setInterpolator(new LinearInterpolator());
ScaleAnimation scaleAnimation = new ScaleAnimation(1, 1, //X Scale
scale, 1, //Y Scale
Animation.RELATIVE_TO_SELF, 0.5f, //X Pivot Point (set to center but it shouldn't matter)
Animation.RELATIVE_TO_SELF, 1.0f); //Y Pivot Point (bottom)
scaleAnimation.setDuration(fadeInFromTopAnimation.getDuration());
shrinkDownAnimation.addAnimation(scaleAnimation);
m_editText.startAnimation(shrinkDownAnimation);
}
public void onAnimationEnd(Animation anim) {}
public void onAnimationRepeat(Animation anim) {}
});
activateView.startAnimation(fadeInFromTopAnimation);
А вот мой fade_in_from_top.xml
файл анимации:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android = "http://schemas.android.com/apk/res/android"
android:interpolator = "@android:anim/linear_interpolator">
<alpha
android:fromAlpha = "0"
android:toAlpha = "1"
android:duration = "500">
</alpha>
<scale
android:fromXScale = "1"
android:fromYScale = "0"
android:toXScale = "1"
android:toYScale = "1"
android:pivotX = "50%"
android:pivotY = "0%"
android:duration = "500">
</scale>
</set>