我想创建一个翻译动画,它会从屏幕顶部弹出一个视图。现在我需要将我的视图放在屏幕上方,以便它不可见。所有视图的根都是垂直LinearLayout
。这就是我将RelativeLayout
(它将被动画化)膨胀到我的LinearLayout中的方式。
final LinearLayout root = (LinearLayout) findViewById (R.id.mainLayout);
final RelativeLayout container = (RelativeLayout)
LayoutInflater.from(getBaseContext()).
inflate(R.layout.animated_layout ,
root , false );
root.addView(container);
这是Relativelayout xml。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/list_item_back1" >
<TextView
android:textSize="25sp"
android:layout_width = "match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
答案 0 :(得分:0)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<translate
android:fromYDelta="100%"
android:toYDelta="0%"
android:duration="1000" />
</set>
在你的java代码中做这样的事情:
Animation translateAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate_animation);
translateAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
yourAnimatedView.setvisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
yourAnimatedView.startAnimation(translateAnimation);
});