我不知道如何在菜单中使用。但我使用 Layout 做了同样的效果。我放的代码可能对你有帮助。
您必须根据您的要求更改布局。
activity_main.xml
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buy" />
<Button
android:id="@+id/btn_ex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_ex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/linearLayout1"
android:layout_alignParentRight="true"
android:layout_marginBottom="18dp"
android:layout_marginRight="104dp"
android:gravity="bottom"
android:orientation="vertical"
android:visibility="invisible"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example4" />
</LinearLayout>
顶部.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2500"
android:fromXDelta="0%"
android:fromYDelta="200%"
android:toXDelta="0%"
android:toYDelta="0%"
android:zAdjustment="normal" />
MainActivity.java
public class MainActivity extends Activity implements AnimationListener {
private Button btn_ex;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_ex = (Button) findViewById(R.id.btn_ex);
btn_ex.setOnClickListener(new OnClickListener() {
private LinearLayout layout_ex;
public void onClick(View v) {
Animation movement5;
layout_ex = (LinearLayout) findViewById(R.id.layout_ex);
layout_ex.setVisibility(View.VISIBLE);
// layout3.setVisibility(true); //USE THIS LINE //EDITED
movement5 = AnimationUtils.loadAnimation(MainActivity.this,
R.layout.top);
movement5.reset();
movement5.setFillAfter(true);
movement5.setAnimationListener(MainActivity.this);
layout_ex.startAnimation(movement5);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
}
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
}