Shared Element Transition

  • 5 Antworten
  • Letztes Antwortdatum
A

adriax2307

Neues Mitglied
0
Hallo Leute,

leider finde ich im Netz nicht wirklich was :/
Also mal zu meinen beiden Activities:

ActivityA:
-5x CardViews -> Jede hat ein ImageView und ein TextView

ActivityB:
- ImageView
- verschiedene Informationen

Nun habe ich es endlich hinbekommen, dass das Image aus ActivityA per Transition zu ActivityB einen sauberen Übergang macht.
Jetzt stellt sich mir aber die Frage, wie bekomme ich genau das Bild aus AcitivtyA zu ActivityB und vorallem wie kann ich die anderen Informationen zuweisen??
Jede CardView in ActivityA hat ein anderes Bild und einen anderen Inhalt in der TextView.
In ActivityB sind dann zusätzlich noch andere Informationen enthalten.

Kann mir jemand Tipps geben wie ich dies bewerkstelligen kann?

Mfg

Adriax2307
 
Also auf die Stelle könnte ich mir "ids" oder ähnliches in dem Element vorstellen, welches den ClickListener hat. Dabei kannst du setTag() und getTag() benutzen.

Danach wäre natürlich ein Intent die Lösung für die Übergabe der Daten an die zweite Activity.
 
so sieht derzeit mein onClick aus.


Code:
public void onClick(View v) {
        v.setTransitionName("img");

        //ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(this,v, v.getTransitionName());
        Intent intent = new Intent(this, ActivitySharedB.class);
        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this,
                Pair.create(v, v.getTransitionName()));
        startActivity(intent, options.toBundle());

    }

nun die Frage wie ich das Image von z.B. card1 bekomme und an das in ActivityB befindliche ImageView weitergeben, sowie auch die TextViews :/
 
Hallo,
hatte mal vor ein paar Monaten ne kleine Test-Demo dazu angefertigt:
Code:
package com.weirdidea.pepperonas.
sharedelement;

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;


public class ActivityOne extends Activity {

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

  final Button button = (Button) findViewById(R.id.btn_start);

  final View androidRobotView = findViewById(R.id.iv_paranoid);

  button.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View view) {
  Intent intent = new Intent(ActivityOne.this, ActivityTwo.class);
  ActivityOptions options = ActivityOptions
  .makeSceneTransitionAnimation(ActivityOne.this, androidRobotView, "xyz_yo_man");

  startActivity(intent, options.toBundle());
  }
  });
  }


}

-----------------------

package com.weirdidea.pepperonas.sharedelement;

import android.app.Activity;
import android.os.Bundle;


public class ActivityTwo extends Activity {

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

  }

}

--------------------------

<RelativeLayout 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"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingBottom="@dimen/activity_vertical_margin"
  tools:context=".ActivityOne">

  <ImageView
  android:id="@+id/iv_paranoid"
  android:transitionName="xyz_yo_man"
  android:layout_width="60dp"
  android:layout_height="60dp"
  android:scaleType="centerCrop"
  android:src="@drawable/paranoid"/>

  <Button
  style="?android:attr/buttonStyleSmall"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Transition"
  android:id="@+id/btn_start"
  android:layout_alignParentBottom="true"
  android:layout_alignParentStart="true"
  android:layout_marginBottom="48dp"/>


</RelativeLayout>

-----------------------------------
<RelativeLayout 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"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingBottom="@dimen/activity_vertical_margin"
  tools:context="com.weirdidea.pepperonas.sharedelement.ActivityTwo">

  <ImageView
  android:id="@+id/image_small"
  android:transitionName="xyz_yo_man"
  android:layout_width="60dp"
  android:layout_height="60dp"
  android:layout_alignParentRight="true"
  android:layout_alignParentEnd="true"
  android:scaleType="centerCrop"
  android:src="@drawable/paranoid"/>

</RelativeLayout>
 
Das Hier sind die beiden Activities.

Bei einem Klick auf die Qualle soll per Shared Element Transition das Bild bei ActivityB gesetzt werden.
ActivityA.PNG ActivityB.PNG
 
Jemand tipps?
 
Zurück
Oben Unten