ログインフォームで簡単なアクティビティを作成しようとしています。私がやりたいことは、サインイン ボタンのすぐ上にアプリケーションのロゴを配置し、ユーザーがサインイン ボタンを押すと、ロゴが少し上にスライドし、ロゴとサインイン ボタンの間にログイン フォーム (ユーザー名、パスワード フィールド) フェードインします。私は Android アニメーションの初心者なので、助けてください。
私は次のレイアウトを持っています:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:src="@drawable/logo"
android:layout_centerHorizontal="true"
android:layout_above="@+id/login_form"/>
<LinearLayout android:id="@id/login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_above="@+id/sign_in"
android:visibility="gone">
<EditText android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginBottom="8dp"
android:textColor="@color/Black"
android:textColorHint="@color/Black"
android:textIsSelectable="false"
android:hint="@string/username"/>
<EditText android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="48dp"
android:inputType="textPassword"
android:textColor="@color/Black"
android:textColorHint="@color/Black"
android:textIsSelectable="false"
android:hint="@string/password"/>
</LinearLayout>
<Button android:id="@id/sign_in"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:layout_alignParentBottom="true"
android:textColor="@color/White"
android:textSize="18sp">
</RelativeLayout>
以下のアニメーションのいずれかを使用すると、ロゴが数ピクセル上に突然ジャンプしてからフォームがフェードインするか、数ピクセル上にスライドしてから突然上にジャンプしてからフォームがフェードインします。
mForm.setAlpha(0.0f);
mForm.setScaleX(0.0f);
mForm.setScaleY(0.0f);
mForm.setVisibility(View.VISIBLE);
mForm.animate()
.alpha(1.0f)
.scaleX(1.0f)
.scaleY(1.0f)
.setInterpolator(new AccelerateDecelerateInterpolator())
.setDuration(mAnimationDurationMedium);
<>
mLogo.animate()
.translationYBy(mDisplayMetrisUtils.dpToPixels(-96.0f))
.setDuration(mAnimationDurationMedium)
.setInterpolator(new AccelerateDecelerateInterpolator())
.withEndAction(new Runnable() {
@Override
public void run() {
mForm.setAlpha(0.0f);
mForm.setScaleX(0.0f);
mForm.setScaleY(0.0f);
mForm.setVisibility(View.VISIBLE);
mForm.animate()
.alpha(1.0f)
.scaleX(1.0f)
.scaleY(1.0f)
.setInterpolator(new AccelerateDecelerateInterpolator())
.setDuration(mAnimationDurationMedium);
}
});
<>
mForm.setAlpha(0.0f);
mForm.setScaleX(0.0f);
mForm.setScaleY(0.0f);
mForm.setVisibility(View.VISIBLE);
mForm.animate()
.alpha(1.0f)
.scaleX(1.0f)
.scaleY(1.0f)
.setInterpolator(new AccelerateDecelerateInterpolator())
.setDuration(mAnimationDurationMedium)
.withStartAction(new Runnable() {
@Override
public void run() {
mLogo.animate()
.translationYBy(-mForm.getHeight())
.setInterpolator(new AccelerateDecelerateInterpolator())
.setDuration(mAnimationDurationMedium);
}
});
LinearLayout の x および y スケールを 0 に設定しても理解できることから、VISIBLE になると、スケールが 0 に設定されていても、一度に表示するために必要なすべてのピクセルを占有するため、突然上向きにジャンプしますロゴ。私が達成したいのは、 LinearLayout が徐々により多くのスペースを占有し、ロゴにスムーズなスライド効果を持たせることです。
闇の帝王に祈りを捧げてみましたが、成功しませんでした。誰かが私に欠けているものを教えて、正しい方向に向けることができますか? LinearLayout の高さを 0dp から wrap_content に変換するアニメーションを作成する方法はありますか?
前もってありがとう、ディミトリス。