问题
hi i am making an app where i'm basically i have two activities. In first activity i have one textview and imageview and in imageview i have set a layerlist as background and same goes for the second activity. Now my problem is that when i apply shared element transition animation in first activity then both the textview and imageview are animated but layerlist in second activity losses its shape you can see the below images.
and
Now screens with animation
Now from the above images you easily see the difference when i use animation the image in second screen losses its shape i searched all over the internet but didnt get any proper solution so please if someone can help me out here.
my first activity.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:id="@+id/activity_simple_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".newactivities.NewActivity"
android:background="@color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/login_text"
android:transitionName="login_text"
android:textSize="25sp"
android:textColor="@color/White"
android:layout_marginTop="215dp"/>
<ImageView
android:id="@+id/simple_activity_a_imageView"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="80dp"
android:scaleType="centerCrop"
android:src="@drawable/login_page_curve"
android:contentDescription="@string/lion"
android:transitionName="@string/simple_activity_transition"
tools:ignore="UnusedAttribute" />
<Button
android:id="@+id/simple_activity_a_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:visibility="gone"
android:layout_marginBottom="19dp"
android:text="@string/lion" />
</RelativeLayout>
My First Activity.java
public class NewActivity extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new);
// getWindow().setEnterTransition(null);
//getWindow().setExitTransition(null);
final ImageView imageView = (ImageView) findViewById(R.id.simple_activity_a_imageView);
final TextView textView = (TextView)findViewById(R.id.login_text);
Button button = (Button) findViewById(R.id.simple_activity_a_btn);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(NewActivity.this, New2Activity.class);
Pair[] pairs = new Pair[2];
pairs[0] = new Pair<View,String>(imageView,
ViewCompat.getTransitionName(imageView));
pairs[1] = new Pair<View,String>(textView,ViewCompat.getTransitionName(textView));
//pairs[2] = new Pair<View,String>(register_text,getResources().getString(R.string.register_text_transition));
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation
(NewActivity.this,pairs);
startActivity(intent,optionsCompat.toBundle());
}
});
}
public void gotoregister(View view) {
}
}
my layerlist xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle"/>
</item>
<item
android:bottom="-880dp"
android:left="-280dp"
android:right="-280dp"
android:top="0dp">
<shape android:shape="oval">
<solid android:color="@color/White" />
</shape>
</item>
</layer-list>
and my second layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_simple_two"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".newactivities.New2Activity"
android:background="@color/colorPrimary">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Or Login"
android:textSize="30sp"
android:transitionName="login_text"
android:textColor="@color/White"
/>
</LinearLayout>
</RelativeLayout>
<ImageView
android:layout_marginTop="80dp"
android:id="@+id/simple_activity_b_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:src="@drawable/login_page_curve"
android:contentDescription="lion"
android:transitionName="@string/simple_activity_transition"
tools:ignore="UnusedAttribute" />
</LinearLayout>
adb output
TASK com.mikescamell.sharedelementtransitions id=3129
ACTIVITY com.mikescamell.sharedelementtransitions/.newactivities.New2Activity 2dfe0dbc pid=12919
Local FragmentActivity 1fe8aa49 State:
mCreated=truemResumed=true mStopped=false mReallyStopped=false
mLoadersStarted=true
FragmentManager misc state:
mHost=android.support.v4.app.FragmentActivity$HostCallbacks@29e1f212
mContainer=android.support.v4.app.FragmentActivity$HostCallbacks@29e1f212
mCurState=5 mStateSaved=false mDestroyed=false
View Hierarchy:
com.android.internal.policy.impl.PhoneWindow$DecorView{1f58ae7b V.ED.... ... 0,0-540,960}
android.widget.LinearLayout{c0df498 V.E..... ... 0,0-540,888}
android.view.ViewStub{2807a4f1 G.E..... ... 0,0-0,0 #1020370}
android.widget.FrameLayout{22e8d8d6 V.E..... ... 0,38-540,888}
android.support.v7.widget.ActionBarOverlayLayout{1ab9b757 V.E..... ... 0,0-540,850 #7f080034 app:id/decor_content_parent}
android.support.v7.widget.ContentFrameLayout{1b39c244 V.E..... ... 0,84-540,850 #1020002 android:id/content}
android.widget.LinearLayout{1c29bb5f V.E..... ... 0,0-540,766 #7f080016 app:id/activity_simple_two}
android.widget.RelativeLayout{35609f2d V.E..... ... 0,0-540,61}
android.widget.LinearLayout{3471ac62 V.E..... ... 186,0-354,61}
android.support.v7.widget.AppCompatTextView{25b3b7b9 V.ED.... ... 0,0-168,61}
android.support.v7.widget.AppCompatImageView{2195c7fe V.ED.... ... 0,181-540,766 #7f0800a9 app:id/simple_activity_b_image}
android.support.v7.widget.ActionBarContainer{3f55e9ac V.ED.... ... 0,0-540,84 #7f080003 app:id/action_bar_container}
android.support.v7.widget.Toolbar{2cb871f3 V.E..... ... 0,0-540,84 #7f080001 app:id/action_bar}
android.support.v7.widget.AppCompatTextView{1232beb0 V.ED.... ... 24,21-394,62}
android.support.v7.widget.ActionMenuView{21d50129 V.E..... ... 540,0-540,84}
android.support.v7.widget.ActionBarContextView{1cc22cae G.E..... ... 0,0-0,0 #7f080009 app:id/action_context_bar}
android.view.View{bcf1675 V.ED.... ... 0,0-540,38 #102002f android:id/statusBarBackground}
android.view.View{3382660a V.ED.... ... 0,888-540,960 #1020030 android:id/navigationBarBackground}
来源:https://stackoverflow.com/questions/50245524/layer-list-losses-its-shape-in-second-activity-after-applying-animation