在我的应用程序中,我需要用相机进行录制。在录制过程中,我在屏幕上显示一些菜单项。当用户点击一个箭头并在用户触摸屏幕时将其滑入,我需要从屏幕上滑出菜单。Android,动画,如何从屏幕滑入和滑出布局?
我有两个问题。 1)看起来我的动画不起作用。 2)当我设置RelativeLayout为可见/不可见只是视图生效,相机视图不会像你在图像中看到的那样获得整个屏幕(我不想看到黑色背景)。
R.anim.slide_in_up:
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android = "http://schemas.android.com/apk/res/android"
android:fromYDelta = "100%p"
android:toYDelta = "0%p"
android:duration = "3000" />
R.anim.slide_out_up:
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android = "http://schemas.android.com/apk/res/android"
android:fromYDelta = "0%p"
android:toYDelta = "100%p"
android:duration = "3000" />
代码,用于示出slide_in_up:
rlMenu = (RelativeLayout) findViewById(R.id.rlMenu);
imHide = (ImageView) findViewById(R.id.btn_hide);
imHide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rlMenu.setVisibility(View.INVISIBLE);
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
}
});
代码,用于显示slide_out_up:
@Override
public boolean onTouchEvent(MotionEvent event) {
rlMenu.setVisibility(View.VISIBLE);
overridePendingTransition(R.anim.slide_out_up, R.anim.slide_in_up);
return super.onTouchEvent(event);
}
屏幕布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:orientation = "vertical" >
<FrameLayout
android:id = "@+id/camera_preview"
android:layout_width = "fill_parent"
android:layout_height = "0dip"
android:layout_weight = "1" />
<RelativeLayout
android:id = "@+id/rlMenu"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:orientation = "horizontal" >
<RelativeLayout
android:layout_width = "240dip"
android:layout_height = "50dip"
android:background = "@drawable/btn_top_edge_right"
android:layout_alignParentLeft = "true" >
<ImageView
android:id = "@+id/btn_hide"
android:layout_width = "40dip"
android:layout_height = "wrap_content"
android:src = "@drawable/btn_record_hide"
android:layout_marginTop = "10dip"
android:layout_marginBottom = "10dip"
android:contentDescription = "@string/menu_contentdescription"
android:scaleType = "fitXY" />
<ImageView
android:id = "@+id/btn_record"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/btn_record_start"
android:layout_toRightOf = "@id/btn_hide"
android:layout_margin = "10dip"
android:contentDescription = "@string/menu_contentdescription" />
<ImageView
android:id = "@+id/btn_stop"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:src = "@drawable/btn_record_stop"
android:layout_toRightOf = "@id/btn_record"
android:layout_marginTop = "10dip"
android:layout_marginBottom = "10dip"
android:contentDescription = "@string/menu_contentdescription"
android:clickable = "false" />
</RelativeLayout>
<Button
android:id = "@+id/btn_done"
android:layout_width = "wrap_content"
android:layout_height = "50dip"
android:background = "@drawable/btn_record_done"
android:layout_alignParentRight = "true"
android:text = "@string/Record_btn"
android:paddingLeft = "15dip"
style = "@style/simpletopic.bold" />
</RelativeLayout>
</LinearLayout>
如何删除整个的RelativeLayout和放大相机视图与我的动画? 谢谢
你有没有解决动画的问题? – 2012-10-17 07:56:07