-1

I’m working on a project in which I have to do a shared transition. I want to perform a transition on an ImageView from my splash Activity [First Activity] to Login Activity [Second Activity] which has the ImageView in a Fragment. The Image in my 1st Activity and The Image in the fragment of my 2nd Activity are same and Shares The Same Transition Name. I’m unable to perform the transition.

My Splash Activity Code is This

public class Splash extends Activity implements View.OnClickListener{

private ImageView imageView;
private String SharedElementname;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //getWindow().setExitTransition(R.transition.shared_element_transition_a);
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().setSharedElementExitTransition(TransitionInflater.from(this).inflateTransition(R.transition.shared_element_transition_a));
    }
    setContentView(R.layout.activity_splash);
    imageView = (ImageView)findViewById(R.id.splashimage);
    SharedElementname = getString(R.string.sharedname);
    imageView.setOnClickListener(this);

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_splash, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressLint("NewApi")
@Override
public void onClick(View v) {
    ActivityOptionsCompat compat = ActivityOptionsCompat.makeSceneTransitionAnimation(this,v,SharedElementname);
    Intent intent = new Intent(this, LoginActivity.class);
    ActivityCompat.startActivity(this, intent, compat.toBundle());
}

My Login Activity Code @Override protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
if(BuildConfig.MINT_API_ENABLED) {
    Mint.initAndStartSession(LoginActivity.this, BuildConfig.MINT_API_KEY);
}
if (Build.VERSION.SDK_INT >= 21) {
    getWindow().setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.shared_element_transition_a));
}
setContentView(R.layout.activity_login);
} 
Some More Codes….
*****************************************************************************

My Fragment Code Within Login Activty

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loginTab = new LoginTab();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    setSharedElementReturnTransition(TransitionInflater.from(
            getActivity()).inflateTransition(R.transition.shared_element_transition_a));
    setExitTransition(TransitionInflater.from(
            getActivity()).inflateTransition(android.R.transition.fade));

    loginTab.setSharedElementEnterTransition(TransitionInflater.from(
            getActivity()).inflateTransition(R.transition.shared_element_transition_a));
    loginTab.setEnterTransition(TransitionInflater.from(
            getActivity()).inflateTransition(android.R.transition.fade));
}

}

Some More Codes….
*************************************************************************************

My Splash Activity XML File

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_new"
android:orientation="vertical"
android:weightSum="1">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:id="@+id/SplashLayout"
    >

    <ImageView
        android:id="@+id/splashimage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/eventifyd_logo"
        android:transitionName="@string/sharedname"
        />



</RelativeLayout>
</LinearLayout>

My Transition XML File [Shared_element_transition]

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android" android:duration="5000">
<changeTransform />
<changeBounds />
<!—
I also tied ChangeImageTranform But Nothing Happened
-->
</transitionSet>

My Fragment XML File

<LinearLayout
 android:layout_width="match_parent"
 android:layout_marginTop="20dp"
 android:layout_weight="1"
 android:layout_height="match_parent"
 android:orientation="vertical"
 >



    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        >

        <ImageView
            android:id="@+id/profile_pic_login"
            android:layout_above="@+id/login_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:src="@drawable/eventifyd_logo"
            android:transitionName="@string/sharedname"
            />

        <TextView
            android:layout_marginTop="30dp"
            android:id="@+id/login_text"
            android:layout_alignParentBottom="true"

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/login_text"
            style="@style/thin.white.large"/>

    </RelativeLayout>

</LinearLayout> 
Abhinash
  • 368
  • 2
  • 13
  • Can you elaborate as to what "I’m unable to perform the transition" means – rcbevans Sep 22 '15 at 10:38
  • The Transition of the Image From My 1st Activity to The Fragment Activity is not Happening. Its like i want to transition like the LiknedIn App's Splash Screen. the Image In my 1st Activity Should be going to the bottom of my second activity [Which is in Fragment] and should also enlarge a bit. I'm unable to post an image otherwise i would have illustrated you by that. – Abhinash Sep 22 '15 at 10:49
  • Are transitions enabled in your theme? Else try adding `getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);` – rcbevans Sep 22 '15 at 11:04
  • Yes it is Enable in my theme. If have also tried what you have suggested, but it still doesn't work. My testing Device has Lolipop API 21 in it. – Abhinash Sep 22 '15 at 11:07

1 Answers1

0

I couldn't do it the way i was try. I changed the Fragments to Activity and it worked as a charm. I think Making transition from Activity to a Fragment of another activity is not Possible. Anyway, My this approach worked.

Abhinash
  • 368
  • 2
  • 13