嗨,我正在制作一个应用程序,我基本上我有两个活动。在第一个活动中,我有一个textview和imageview,在imageview中我已经设置了一个图层列表作为背景,同样适用于第二个活动。 现在我的问题是,当我在第一个活动中应用共享元素过渡动画时,textview和imageview都是动画的,但第二个活动中的layerlist会丢失它的形状,你可以看到下面的图像。
现在有动画的屏幕
现在从上面的图片中你很容易看到我使用动画时的差异,第二个屏幕中的图像失去了我在互联网上搜索的形状,但没有得到任何正确的解决方案所以如果有人可以帮助我在这里请。
我的第一个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) {
}
}
我的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>
和我的第二个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输出
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}