Best sample use two activity communication animation.
actvity_main.xml
<?xml version="1.0" encoding="utf-8"?>
Thank you
actvity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.samset.recycleranimation.MainActivity">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rv" />
</RelativeLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.samset.recycleranimation.MainActivity">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rv" />
</RelativeLayout>
ActivityMain.java
package com.samset.recycleranimation;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import com.samset.recycleranimation.activities.SecondActivity;
import com.samset.recycleranimation.adapter.RecyclerAdapter;
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
String[] data, language;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
data = getResources().getStringArray(R.array.country);
language = getResources().getStringArray(R.array.language);
recyclerView = (RecyclerView) findViewById(R.id.rv); // layout reference
LinearLayoutManager llm = new LinearLayoutManager(this);
recyclerView.setLayoutManager(llm);
recyclerView.setHasFixedSize(true); // to improve performance
recyclerView.setAdapter(new RecyclerAdapter(data, language)); // the data manager is assigner to the RV
recyclerView.addOnItemTouchListener( // and the click is handled
new RecyclerClickListener(this, new RecyclerClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra(SecondActivity.ID, data[position]);
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
MainActivity.this,
new Pair<View, String>(view.findViewById(R.id.CONTACT_city),
getString(R.string.transition_name_city)),
new Pair<View, String>(view.findViewById(R.id.country_flag),
getString(R.string.transition_name_flag)),
new Pair<View, String>(view.findViewById(R.id.country_name),
getString(R.string.transition_name_name)),
new Pair<View, String>(view.findViewById(R.id.country_lang),
getString(R.string.transition_name_lang))
);
ActivityCompat.startActivity(MainActivity.this, intent, options.toBundle());
}
}));
}
public static class RecyclerClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;
GestureDetector mGestureDetector;
public interface OnItemClickListener {
public void onItemClick(View view, int position);
}
public RecyclerClickListener(Context context, OnItemClickListener listener) {
mListener = listener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
View childView = view.findChildViewUnder(e.getX(), e.getY());
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
mListener.onItemClick(childView, view.getChildPosition(childView));
return true;
}
return false;
}
@Override
public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean b) {
}
}
}
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import com.samset.recycleranimation.activities.SecondActivity;
import com.samset.recycleranimation.adapter.RecyclerAdapter;
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
String[] data, language;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
data = getResources().getStringArray(R.array.country);
language = getResources().getStringArray(R.array.language);
recyclerView = (RecyclerView) findViewById(R.id.rv); // layout reference
LinearLayoutManager llm = new LinearLayoutManager(this);
recyclerView.setLayoutManager(llm);
recyclerView.setHasFixedSize(true); // to improve performance
recyclerView.setAdapter(new RecyclerAdapter(data, language)); // the data manager is assigner to the RV
recyclerView.addOnItemTouchListener( // and the click is handled
new RecyclerClickListener(this, new RecyclerClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra(SecondActivity.ID, data[position]);
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
MainActivity.this,
new Pair<View, String>(view.findViewById(R.id.CONTACT_city),
getString(R.string.transition_name_city)),
new Pair<View, String>(view.findViewById(R.id.country_flag),
getString(R.string.transition_name_flag)),
new Pair<View, String>(view.findViewById(R.id.country_name),
getString(R.string.transition_name_name)),
new Pair<View, String>(view.findViewById(R.id.country_lang),
getString(R.string.transition_name_lang))
);
ActivityCompat.startActivity(MainActivity.this, intent, options.toBundle());
}
}));
}
public static class RecyclerClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;
GestureDetector mGestureDetector;
public interface OnItemClickListener {
public void onItemClick(View view, int position);
}
public RecyclerClickListener(Context context, OnItemClickListener listener) {
mListener = listener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
View childView = view.findChildViewUnder(e.getX(), e.getY());
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
mListener.onItemClick(childView, view.getChildPosition(childView));
return true;
}
return false;
}
@Override
public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean b) {
}
}
}
secondactivity.xml
<LinearLayout 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:orientation="vertical">
<ImageView
android:id="@+id/myHeader"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="82dp"
android:padding="@dimen/activity_vertical_margin">
<ImageView
android:id="@+id/DETAILS_circle"
android:layout_width="48dp"
android:layout_height="48dp"
android:transitionName="@string/transition_name_flag"
android:background="@drawable/circle"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"/>
<TextView
android:id="@+id/DETAILS_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jonh Doe"
android:transitionName="@string/transition_name_name"
android:layout_toRightOf="@+id/DETAILS_circle"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_centerVertical="true"
android:textColor="#000"
android:textSize="25sp"/>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="@dimen/activity_horizontal_margin"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/DETAILS_phone_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone:"
android:textColor="#000"
android:textSize="20sp"/>
<TextView
android:id="@+id/DETAILS_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:transitionName="@string/transition_name_lang"
android:layout_toRightOf="@+id/DETAILS_phone_label"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:text="+01 123456789"
android:textColor="#9f9f9f"
android:textSize="20sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/DETAILS_email_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email:"
android:textColor="#000"
android:textSize="20sp"/>
<TextView
android:id="@+id/DETAILS_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/DETAILS_email_label"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:text="jonh.doe@example.com"
android:textColor="#9f9f9f"
android:textSize="20sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/DETAILS_city_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City:"
android:textColor="#000"
android:textSize="20sp"/>
<TextView
android:id="@+id/DETAILS_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/DETAILS_city_label"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:transitionName="@string/transition_name_city"
android:text="Rome"
android:textColor="#9f9f9f"
android:textSize="20sp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/myHeader"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="82dp"
android:padding="@dimen/activity_vertical_margin">
<ImageView
android:id="@+id/DETAILS_circle"
android:layout_width="48dp"
android:layout_height="48dp"
android:transitionName="@string/transition_name_flag"
android:background="@drawable/circle"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"/>
<TextView
android:id="@+id/DETAILS_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jonh Doe"
android:transitionName="@string/transition_name_name"
android:layout_toRightOf="@+id/DETAILS_circle"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_centerVertical="true"
android:textColor="#000"
android:textSize="25sp"/>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="@dimen/activity_horizontal_margin"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/DETAILS_phone_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone:"
android:textColor="#000"
android:textSize="20sp"/>
<TextView
android:id="@+id/DETAILS_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:transitionName="@string/transition_name_lang"
android:layout_toRightOf="@+id/DETAILS_phone_label"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:text="+01 123456789"
android:textColor="#9f9f9f"
android:textSize="20sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/DETAILS_email_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email:"
android:textColor="#000"
android:textSize="20sp"/>
<TextView
android:id="@+id/DETAILS_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/DETAILS_email_label"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:text="jonh.doe@example.com"
android:textColor="#9f9f9f"
android:textSize="20sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/DETAILS_city_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City:"
android:textColor="#000"
android:textSize="20sp"/>
<TextView
android:id="@+id/DETAILS_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/DETAILS_city_label"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:transitionName="@string/transition_name_city"
android:text="Rome"
android:textColor="#9f9f9f"
android:textSize="20sp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
SecondActivity.java
package com.samset.recycleranimation.activities;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import com.samset.recycleranimation.R;
public class SecondActivity extends AppCompatActivity {
public final static String ID = "ID";
String countryName;
private TextView mName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
countryName=getIntent().getStringExtra(ID);
mName = (TextView) findViewById(R.id.DETAILS_name);
mName.setText(countryName);
}
}
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import com.samset.recycleranimation.R;
public class SecondActivity extends AppCompatActivity {
public final static String ID = "ID";
String countryName;
private TextView mName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
countryName=getIntent().getStringExtra(ID);
mName = (TextView) findViewById(R.id.DETAILS_name);
mName.setText(countryName);
}
}
Thank you
No comments:
Post a Comment