使用Transition Framework还原或重置场景

时间:2016-11-15 07:32:34

标签: android android-animation

我正在关注tutorial并希望自己做一些事情。教程向我展示了如何制作动画。所以我这样做了,现在我想恢复以前的视图(场景)。首先是淡入新视图,这可以正常工作,但恢复/重置失败。 应该的行为如下:

enter image description here

我将<?php $curl = curl_init(); $data = file_get_contents('C:\test.png'); curl_setopt_array($curl, array( CURLOPT_URL => "http://woo.dev/wp-json/wp/v2/media", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_HTTPHEADER => array( "authorization: Basic XxxxxxxXxxxxXx=", "cache-control: no-cache", "content-disposition: attachment; filename=test.png", "content-type: image/png", ), CURLOPT_POSTFIELDS => $data, )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } 设置为菜单条(ImageView),并切换onClickListener值以检查视图是否已满。我遇到的一个问题是,当tansition结束时我不得不重新分配boolean,因为新的布局在转换中正在膨胀。但是当我在三个按钮可见后点击时,它没有注册我的点击(通过我检查的调试)。

这是代码文件:

onClickListener

以下是xml文件:

活动布局:

public class HorizotalViewActivity extends AppCompatActivity implements Transition.TransitionListener, View.OnClickListener
{


    boolean viewing = false;
    ImageView goButton;
    Scene scene, restoreScene;

    @Override
    protected void onCreate( Bundle savedInstanceState )
    {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_horizotal_view );

        ViewGroup sceneView = (ViewGroup) findViewById( R.id.sceneView );


        scene = Scene.getSceneForLayout( sceneView,
                R.layout.transition_example2, this );

        restoreScene = Scene.getSceneForLayout( sceneView,
                R.layout.transition_example, this );


        goButton = (ImageView) findViewById( R.id.goButton );


        goButton.setOnClickListener( this );


    }



    @Override public void onTransitionStart( Transition transition )
    {

    }

    @Override public void onTransitionEnd( Transition transition )
    {
        goButton = (ImageView) findViewById( R.id.goButton );


        goButton.setOnClickListener( this );
    }
//...

    @Override public void onClick( View view )
    {
        if ( !viewing )
        {
            TransitionManager.go( scene );
            viewing = true;
        }
        else
        {


            TransitionManager.go( restoreScene );

            //goToScene( restoreScene );


            viewing = false;
        }
    }
}

默认布局(transition_example.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/sceneView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.lgvalle.material_animations.HorizotalViewActivity">
<include layout="@layout/transition_example"/>

</LinearLayout>

转换布局(transition_example2.xml):

 <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scene"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/goButton"
           android:src="@drawable/menu"
            android:layout_width="60dp"
            android:layout_height="60dp" />

    </LinearLayout>

我看不出我的逻辑问题,它自我解释,

1 - 检查<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scene" android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/goButton" android:src="@drawable/menu" android:layout_width="60dp" android:layout_height="60dp" /> <ImageView android:id="@+id/play" android:layout_marginLeft="15dp" android:src="@drawable/play" android:layout_width="60dp" android:layout_height="60dp" /> <ImageView android:id="@+id/repeat" android:layout_marginLeft="15dp" android:src="@drawable/repeat" android:layout_width="60dp" android:layout_height="60dp" /> <ImageView android:id="@+id/share" android:layout_marginLeft="15dp" android:src="@drawable/share" android:layout_width="60dp" android:layout_height="60dp" /> </LinearLayout> 是否已经发生转换

1A - 转换,更新boolean

2 - 如果发生过渡

2A - 呼叫上一个场景,更新boolean

现在,我想boolean存在这个问题,因为一旦onCickListener被调用,我就无法在onClickListener中找到断点,如果它被注册,它可能会按预期工作。没有TransitionManager.go()错误/警告。

1 个答案:

答案 0 :(得分:2)

我的项目与我发现的相同:

使用场景转换时会发生什么,您有2个将设置动画的视图集。让我们说Set A(开始布局)和Set B(End Layout)。您在代码中执行的操作是在Set A上设置clicklisteners。但是在场景转换集A之后不再出现在屏幕上。

转换后再次设置clicklisteners将解决您的问题。 (当您使用CustomView时,您需要“复制”内容值。

要实现此目的,请使用Scene.setEnterAction(Runnable)方法

scene.setEnterAction(new Runnable(){

@override
void run()
{

   goButton = (ImageView) scene.getSceneRoot.findViewById( R.id.goButton );


   goButton.setOnClickListener( this );

}

});
相关问题