机器人,动漫,如何进出屏幕布局滑动?(Android, animation, How to slid

2019-07-29 03:21发布

在我的应用程序需要通过相机记录。 在拍摄过程中我展示了一些项目,如在屏幕上的菜单。 我需要在用户点击一个箭头从屏幕滑出菜单,滑动时,在用户触摸屏幕。

我有两个问题。 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的和放大相机视图与我的动画? 谢谢

Answer 1:

回答第二个问题。 试着改变你的布局如下:

<?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>

我曾与一个MapView的俗了类似的情况。



Answer 2:

我认为这会工作,如果你使用框架layout.Add两帧,并添加图片到frame.Alternatively添加动画两个框架,使之发挥将会使这项工作out.I认为这会工作,能给你带来什么你wanted.A一小段代码如下所示希望这将有助于你律位。

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);                 

            }


Answer 3:

只是尝试设置的知名度去其他布局元素,所以主视图将得到拉伸。



文章来源: Android, animation, How to sliding in and out a layout from screen?