如何将相对布局添加到具有幻灯片效果的相对布局?

How to add relative layout to relative layout with slide in effect?

我有一个相对布局,我在其中添加了第二个包含 4 个按钮的相对布局。当我做: relativeLayout1.addView(relativeLayout2,params) 我希望添加的带有 4 个按钮的相对布局从右向左滑入。

这有可能吗?

xml:

<translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="500" android:fromXDelta="100%" android:toXDelta="0%" > </translate>

代码: ```

public Panel(Context context) {
    super(context);

    this.setBackgroundColor(Color.BLACK);
    this.setId(R.id.panel);

    right_menubar = new RelativeLayout(context);
    right_menubar.setId(R.id.panel_indicators);

    plp_right_menu_bar = new RelativeLayout.LayoutParams(100, 100);

    this.addView(right_menubar, plp_right_menu_bar);

    Animation fadeIn = AnimationUtils.loadAnimation(context, R.animator.anim);
    right_menubar.startAnimation(fadeIn);

}

而不是 100%0% 使用 100%p0%p

%p 表示其父项的百分比。我想这就是你想要做的。

现在正在运行,

right_menubar.setId(R.id.panel_indicators);
plp_right_menu_bar = new RelativeLayout.LayoutParams(100, 100);
plp_right_menu_bar.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
this.addView(right_menubar, plp_right_menu_bar);
right_menubar.startAnimation(AnimationUtils.loadAnimation(this.getContext(), R.animator.anim));

动画前无需设置为不可见