[英]Why the XML specified transition isn't executed? (or why its specified duration isn't taken account?)
I followed this documentation: https://developer.android.com/training/transitions/start-activity#java . 我遵循了以下文档: https : //developer.android.com/training/transitions/start-activity#java 。
First, I will show you my implementation. 首先,我将向您展示我的实现。 You will find my question at the end of this post.
您将在本文结尾处找到我的问题。
Thus, I modified 4 files: 因此,我修改了4个文件:
<?xml version="1.0" encoding="utf-8"?> <transitionSet xmlns:android="http://schemas.android.com/apk/res/android"> <fade android:fadingMode="fade_in" android:duration="3000" /> </transitionSet>
windowEnterTransition
thanks to fade.xml. windowEnterTransition
定义了windowEnterTransition。 Note that MainActivity's parent, AppTheme, has Material as parent. <!-- Base application theme. --> <style name="AppTheme" parent="android:Theme.Material"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="android:windowActivityTransitions">true</item> </style> <style name="AppTheme.NoActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> </style> <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> <style name="MainActivityTheme" parent="AppTheme"> <item name="android:windowEnterTransition">@transition/fade</item> </style>
<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/MainActivityTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
MainActivity.java
: MainActivity.java
设置了Enter转换: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setEnterTransition(new Fade(Fade.IN)); setContentView(R.layout.activity_main); }
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.."
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
The version of Android installed within the emulator is: 5.1.1 (cf. "About phone" in the settings of Android, in the emulator). 在模拟器中安装的Android版本为:5.1.1(请参见模拟器中Android设置中的“关于手机”)。
However, when I launch my application, the main activity's UI doesn't fade in. Do you know why ? 但是,当我启动应用程序时,主活动的UI不会消失。您知道为什么吗? In other words: Why the XML specified transition isn't executed?
换句话说:为什么不执行XML指定的转换? (or why its specified duration isn't taken account?)
(或者为什么不考虑其指定的持续时间?)
I also tried to move <item name="android:windowActivityTransitions">true</item>
from the theme MainActivityTheme
(file: styles.xml) to the theme AppTheme
(file: the same, ie: styles.xml). 我还尝试将
<item name="android:windowActivityTransitions">true</item>
从主题MainActivityTheme
(文件:styles.xml)移动到主题AppTheme
(文件:相同, 即: styles.xml)。 But it didn't fix this bug. 但是它并不能解决这个错误。
Try This I hope its Work 试试这个,我希望它的工作
Activity transitions in material design apps provide visual connections between different states through motion and transformations between common elements. 材料设计应用程序中的活动过渡通过运动和常见元素之间的转换提供了不同状态之间的可视连接。 You can specify custom animations for enter and exit transitions and for transitions of shared elements
between activities.
您可以为进入和退出过渡以及
between activities.
共享元素的过渡指定自定义动画between activities.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
setContentView(R.layout.activity_main);
}
Also Read This Question This May helps You WindowEnterTransition Not Affecting Activity Transition 还请阅读此问题,这可以帮助您WindowEnterTransition不影响活动过渡
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.