共享TextView元素的活动转换失败

时间:2015-02-16 01:27:25

标签: android android-fragments android-recyclerview android-cardview activity-transition

我正在尝试与Activity共享一个TextView,但TextView的文本没有出现。 CardView位于片段中,当点击某个卡片时,调用此片段的相应活动附件上的方法并启动一个新的活动。

以下是一些小节:

RepositoriesActivity.java

//Activity attached to the Fragment with the Cards
    @Override
    public void onCreate(Bundle savedInstanceState){
        getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
        getWindow().setEnterTransition(new Explode());
        getWindow().setSharedElementExitTransition(new ChangeBounds());
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_repositories);
    }

    //If click was detected in the Card
    public void commonSharedElements(View sharedView){
            //sharedView is a RecyclerView for get the TextView instance
            if(sharedView != null) {
                Toast.makeText(this, "Common Shared Elements Received", Toast.LENGTH_LONG).show();
                Intent intent = new Intent(this, DetailsRepositoriesActivity.class);
                TextView view_description = (TextView) sharedView.findViewById(R.id.description_text);
                //Shared elements
                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this,
                        view_description, "description_text"
                        );
                startActivity(intent, options.toBundle());
            }
        }

card_repositories.xml //片段布局的卡片

<android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view_repos"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="450dip"
        android:layout_margin="7dip"
        android:layout_marginStart="5dip"
        card_view:cardCornerRadius="4dp">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
               <RelativeLayout
                    android:id="@+id/relative_image"
                    android:layout_width="fill_parent"
                    android:layout_height="300dip"
                    android:background="@drawable/landscape">
                   <TextView
                       android:id="@+id/info_text"
                       android:layout_width="match_parent"
                       android:layout_height="wrap_content"
                       android:layout_alignParentBottom="true"
                       android:textSize="40sp"
                       android:textColorHighlight="#FFFFFF"
                       android:background="@color/text_view_repo_title"
                       android:transitionName="info_text"
                   />
               </RelativeLayout>
               <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="fill_parent">
                    <TextView
                        android:id="@+id/description_text"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="2dip"
                        android:textSize="20sp"
                        android:transitionName="description_text"/>
               </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView>

DetailsRepositoriesActivity.java

@Override
    public void onCreate(Bundle savedInstanceState){
        getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
        getWindow().setSharedElementEnterTransition(new ChangeBounds());
        getWindow().setSharedElementExitTransition(new ChangeBounds());
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_details_repositories);
    }

layout_details_repositories.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/description_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:transitionName="description_text"
        android:textSize="32sp"
        android:background="@color/status_color"/>

</LinearLayout>

0 个答案:

没有答案