Android,动画,如何从屏幕上滑入和滑出布局?
在我的应用程序中,我需要用相机记录。在录制过程中,我将一些项目显示为屏幕上的菜单。当用户单击箭头时,我需要从屏幕上滑出菜单,当用户触摸屏幕时,我需要滑入菜单 我有两个问题。 1) 我的动画似乎不起作用。 2) 当我将RelativeLayout设置为visible/invisible(可见/不可见)时,仅视图生效,摄影机视图无法获得图像中显示的整个屏幕(我不希望看到黑色背景) R.anim.slide\u in\u up:Android,动画,如何从屏幕上滑入和滑出布局?,android,animation,layout,slide,Android,Animation,Layout,Slide,在我的应用程序中,我需要用相机记录。在录制过程中,我将一些项目显示为屏幕上的菜单。当用户单击箭头时,我需要从屏幕上滑出菜单,当用户触摸屏幕时,我需要滑入菜单 我有两个问题。 1) 我的动画似乎不起作用。 2) 当我将RelativeLayout设置为visible/invisible(可见/不可见)时,仅视图生效,摄影机视图无法获得图像中显示的整个屏幕(我不希望看到黑色背景) R.anim.slide\u in\u up: <?xml version="1.0" encoding="u
<?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" />
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);
}
});
用于显示幻灯片内容的代码:
<?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" />
@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并用动画放大摄影机视图?
谢谢如果你使用帧布局,我认为这会奏效。添加两个帧并将图片添加到帧中。或者,将动画添加到两个帧并播放会奏效。我认为这会奏效,并为你提供你想要的。下面显示了一小段代码,希望这会对你有所帮助
if (imagesetflag == true) {
Right_to_left_in = AnimationUtils.loadAnimation(this,
R.anim.right_to_left_in);
Right_to_left_out = AnimationUtils.loadAnimation(this,
R.anim.right_to_left_out);
left_to_Right_in = AnimationUtils.loadAnimation(this,
R.anim.left_to_right_in);
Left_to_Right_out = AnimationUtils.loadAnimation(this,
R.anim.left_to_right_out);
frame1.setImageBitmapReset(decryptedimage, 0, true);
frame1.bringToFront();
frame1.setVisibility(View.VISIBLE);
frame2.setVisibility(View.INVISIBLE);
frame1.setAnimation(Right_to_left_in);
frame2.setAnimation(Right_to_left_out);
} else {
Right_to_left_in = AnimationUtils.loadAnimation(this,
R.anim.right_to_left_in);
Right_to_left_out = AnimationUtils.loadAnimation(this,
R.anim.right_to_left_out);
left_to_Right_in = AnimationUtils.loadAnimation(this,
R.anim.left_to_right_in);
Left_to_Right_out = AnimationUtils.loadAnimation(this,
R.anim.left_to_right_out);
frame2.setImageBitmapReset(decryptedimage, 0, true);
frame2.bringToFront();
frame2.setVisibility(View.VISIBLE);
frame1.setVisibility(View.INVISIBLE);
frame2.setAnimation(Right_to_left_in);
frame1.setAnimation(Right_to_left_out);
}
第二个问题的答案。尝试更改布局,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<RelativeLayout
android:id="@+id/rlMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<ImageView
android:id="@+id/btn_hide"
android:layout_width="40dip"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:contentDescription="@string/menu_contentdescription"
android:scaleType="fitXY"
android:src="@drawable/btn_record_hide" />
<ImageView
android:id="@+id/btn_record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:layout_toRightOf="@id/btn_hide"
android:contentDescription="@string/menu_contentdescription"
android:src="@drawable/btn_record_start" />
<ImageView
android:id="@+id/btn_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:layout_toRightOf="@id/btn_record"
android:clickable="false"
android:contentDescription="@string/menu_contentdescription"
android:src="@drawable/btn_record_stop" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_done"
style="@style/simpletopic.bold"
android:layout_width="wrap_content"
android:layout_height="50dip"
android:layout_alignParentRight="true"
android:background="@drawable/btn_record_done"
android:paddingLeft="15dip"
android:text="@string/Record_btn" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
我在使用custum MapView时也遇到过类似的情况。只要试着设置其他布局元素的可见性,主视图就会变长。嗨,Ali jan,谢谢你。你的建议很管用。下一步是如何应用动画。我必须做更多的研究。再次感谢。你们解决动画问题了吗?