gpt4 book ai didi

java - 我尝试在两个 Activity 之间添加动画后应用程序关闭

转载 作者:行者123 更新时间:2023-11-29 04:13:21 28 4
gpt4 key购买 nike

这是我的项目基本结构:

我有 3 个 Activity 如下1)主要 Activity 2)计算 Activity 3)共享 Activity

我只是想在 My CalculateActivity 和 My SharedActivity 之间添加共享 View 动画

当我将 onClick 监听器添加到我的 CalculateActivity 布局时它工作正常但是当我尝试通过此代码添加动画时:

  Intent intent = new Intent(CalculateActivity.this, SharedActivity.class);
Pair<View, String> p1 = Pair.create((View)imageView1, "profile");
Pair<View, String> p2 = Pair.create((View)textView2, "textView7");
Pair<View, String> p3 = Pair.create((View)textView, "textView8");
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(CalculateActivity.this, p1, p2, p3);
startActivity(intent,options.toBundle());

我的应用被关闭了!!

这是我的 list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hp.dateofbirth">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CalculateActivity" />

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />

<activity android:name=".SharedActivity"></activity>
</application>

CalculateActivity 的 XML 文件

<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_image"
android:gravity="center"
android:orientation="vertical"


>

<android.support.constraint.ConstraintLayout
android:transitionName="card_layout_transition"
android:id="@+id/constraintLayout"
android:layout_width="357dp"
android:layout_height="119dp"
android:background="@drawable/card_layout"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:transitionName="@string/blue_button"
android:id="@+id/imageView"
android:layout_width="79dp"
android:layout_height="73dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="15dp"
android:layout_marginRight="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/textView7"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/circle_image" />

<TextView
android:transitionName="text_transition"
android:id="@+id/textView7"
android:layout_width="229dp"
android:layout_height="30dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="23dp"
android:layout_marginRight="23dp"
android:layout_marginBottom="12dp"
android:fontFamily="@font/nunito_extralight"
android:text="Hey You've get something!"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/textView8"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:transitionName="text_transition2"
android:id="@+id/textView8"
android:layout_width="223dp"
android:layout_height="39dp"
android:layout_marginBottom="26dp"
android:text="@string/lorem_ipsum_dolor_sit_amet_consectetur_adipiscing_elit_se"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/textView7"
app:layout_constraintStart_toStartOf="@+id/textView7"
app:layout_constraintTop_toBottomOf="@+id/textView7" />
</android.support.constraint.ConstraintLayout>

SharedActivity 的 XML 代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_image"
android:id="@+id/parent"
tools:context=".SharedActivity">

<android.support.constraint.ConstraintLayout
android:id="@+id/parent1"
android:layout_width="391dp"
android:layout_height="355dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="50dp"
android:layout_marginRight="20dp"
android:background="@drawable/card_layout"
android:transitionName="card_layout_transition">

<ImageView
android:id="@+id/image_id"
android:layout_width="151dp"
android:layout_height="162dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:src="@drawable/circle_image"
android:transitionName="@string/blue_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.44"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView2"
android:layout_width="247dp"
android:layout_height="21dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Hey you've Got something !"
android:textColor="#707070"
android:textSize="15sp"
android:transitionName="text_transition"
app:fontFamily="@font/nunito_extralight"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.595" />

<TextView
android:textColor="@color/textcolor"
android:id="@+id/textView3"
android:layout_width="261dp"
android:layout_height="73dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="8dp"
android:layout_marginBottom="44dp"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing"
android:transitionName="text_transition2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.563"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="1.0" />

</android.support.constraint.ConstraintLayout>

这是我的 Logcat

    com.google.android.apps.gsa.shared.l.c: Failed to connect: 16
at com.google.android.apps.gsa.shared.l.a.b(SourceFile:42)
at com.google.android.apps.gsa.staticplugins.z.c.bvq(SourceFile:12)
at com.google.android.apps.gsa.clockwork.b.a(Unknown Source)
at com.google.android.apps.gsa.staticplugins.s.b.a.a(SourceFile:2)
at com.google.android.apps.gsa.staticplugins.s.b.d.call(Unknown Source)
at com.google.android.libraries.gsa.runner.a.a.c(SourceFile:16)
at com.google.android.libraries.gsa.runner.a.e.bjz(Unknown Source)
at com.google.android.apps.gsa.shared.logger.e.a.a.a.a(SourceFile:55)
at com.google.android.apps.gsa.shared.logger.e.a.a.g.bjz(Unknown Source)
at com.google.common.r.a.ct.eZX(SourceFile:9)
at com.google.common.r.a.bq.run(SourceFile:5)
at com.google.common.r.a.cs.run(SourceFile:9)
at com.google.android.apps.gsa.shared.util.concurrent.b.i.run(Unknown Source)
at com.google.android.apps.gsa.shared.util.concurrent.b.bs.run(SourceFile:3)
at com.google.android.apps.gsa.shared.util.concurrent.b.bs.run(SourceFile:3)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.google.android.apps.gsa.shared.util.concurrent.b.o.run(SourceFile:6)
12-16 16:15:31.446 19642-19647/? E/Sensors: sns_smr_util.c(106):Unable to initialize service 256 with QCCI, timed out (10000 ms)
12-16 16:15:31.447 19642-19647/? E/Sensors: sns_sam_mr.c(1012):Unable to initialize service 0 with QCCI
12-16 16:15:31.447 19642-19647/? E/Sensors: sns_sam_mr.c(1107):Unable to acquire service handle 0
12-16 16:15:31.449 19642-19645/? E/Sensors: sns_reg_la.c(91):reg_read: reg file not open
12-16 16:15:31.449 19642-19647/? E/Sensors: mag_cal.c(1609):mag_cal_sam_init: Unknown UUID(1) 00000000-0000-0000
12-16 16:15:31.449 19642-19645/? E/Sensors: sns_reg.c(291):Received error from sns_reg_read/write 5
12-16 16:15:31.449 19642-19647/? E/Sensors: mag_cal.c(1614):mag_cal_sam_init: Unknown UUID(2) 0000-000000000000
12-16 16:15:31.449 19642-19647/? E/Sensors: sns_sam.c(4433):Failed to register algorithm service 16 with SAM
12-16 16:15:31.450 19642-19645/? E/Sensors: sns_reg_la.c(91):reg_read: reg file not open
12-16 16:15:31.450 19642-19645/? E/Sensors: sns_reg.c(291):Received error from sns_reg_read/write 5
12-16 16:15:31.450 19642-19645/? E/Sensors: sns_reg_la.c(91):reg_read: reg file not open
12-16 16:15:31.450 19642-19645/? E/Sensors: sns_reg.c(291):Received error from sns_reg_read/write 5
12-16 16:15:31.451 19642-19645/? E/Sensors: sns_reg_la.c(91):reg_read: reg file not open
12-16 16:15:31.451 19642-19645/? E/Sensors: sns_reg.c(291):Received error from sns_reg_read/write 5
12-16 16:15:31.452 19642-19645/? E/Sensors: sns_reg_la.c(91):reg_read: reg file not open
12-16 16:15:31.452 19642-19645/? E/Sensors: sns_reg.c(291):Received error from sns_reg_read/write 5
12-16 16:15:31.453 19642-19645/? E/Sensors: sns_reg_la.c(91):reg_read: reg file not open

最佳答案

您可以使用以下代码实现动画:

bottom_down.xml :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1500"
android:fromYDelta="5"
android:toYDelta="90%" />
</set>

bottom_up.xml :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fromYDelta="90%"
android:toYDelta="0" />
</set>

nothing.xml :

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromYDelta="0%p"
android:toYDelta="0%p" />

开始第二个 Activity :

Intent intent = new Intent(CalculateActivity.this, SharedActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.bottom_up, R.anim.nothing);

第二个 Activity 结束时:

@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.nothing, R.anim.bottom_down);
}

你可以根据自己的喜好改变xml动画

关于java - 我尝试在两个 Activity 之间添加动画后应用程序关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53801481/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com