Android转换:转换后无法点击的按钮

时间:2016-07-23 03:28:05

标签: android android-animation android-transitions

我是新手过渡并尝试一个基本的例子。有两个按钮," DOWN"并且" UP",在布局中。如果单击" DOWN",则两个按钮都应向下移动到屏幕底部。如果单击" UP",两个按钮都应该向上移动到屏幕顶部。

" DOWN"按钮按预期工作,但当我点击" UP"按钮,除按钮上的涟漪效果外没有任何其他事情发生。我在" UP"中插入了Log语句。按钮的onClick(),但不会被调用。

请指出我做错了什么。

这是回购。 https://github.com/gs20060101/TransitionExperiments.git

以下是一些相关文件。

MainActivityFragment.java

public class MainActivityFragment extends Fragment {

    private Scene mScene1;
    private Scene mScene2;

    public MainActivityFragment() {
    }

    @Override
    public View onCreateView(
        LayoutInflater inflater,
        ViewGroup container,
        Bundle savedInstanceState
    ) {

        View rootView = inflater.inflate(R.layout.fragment_main, container, false);

        ViewGroup sceneRoot = (ViewGroup) rootView.findViewById(R.id.scene_root);

        mScene1 = new Scene(sceneRoot, (ViewGroup) sceneRoot.findViewById(R.id.scene));

        mScene2 = Scene.getSceneForLayout(
            sceneRoot,
            R.layout.fragment_transition_scene_2,
            getActivity()
        );

        Button downButton = (Button) rootView.findViewById(R.id.downButton);
        downButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TransitionManager.go(mScene2);
            }
        });

        Button upButton = (Button) rootView.findViewById(R.id.upButton);
        upButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TransitionManager.go(mScene1);
            }
        });

        return rootView;
    }
}

fragment_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    android:id="@+id/scene_root"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.gens.transitionplay.MainActivityFragment">

    <include layout="@layout/fragment_transition_scene_1"/>

</FrameLayout>

fragment_transition_scene_1.xml

<?xml version="1.0" encoding="utf-8"?>

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

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"/>

    <Button
        android:id="@+id/downButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView"
        android:text="Go"/>

    <Button
        android:id="@+id/upButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/downButton"
        android:layout_toRightOf="@id/downButton"
        android:text="Back"/>

</RelativeLayout>

fragment_transition_scene_2.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout

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

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"/>

    <Button
        android:id="@+id/downButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Down"/>


    <Button
        android:id="@+id/upButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/downButton"
        android:layout_toRightOf="@id/downButton"
        android:text="Up"/>

</RelativeLayout>

0 个答案:

没有答案