为什么不执行XML指定的转换? (或者为什么不考虑其指定的持续时间?) [英] Why the XML specified transition isn't executed? (or why its specified duration isn't taken account?)

查看:103
本文介绍了为什么不执行XML指定的转换? (或者为什么不考虑其指定的持续时间?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了以下文档: 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.

因此,我修改了4个文件:

Thus, I modified 4 files:

  1. fade.xml,它定义过渡时淡入的持续时间.

<?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>

  1. values/styles.xml,它通过fade.xml定义了windowEnterTransition.请注意,MainActivity的父AppTheme以Material为父.
  1. values/styles.xml, which defines the windowEnterTransition thanks to fade.xml. 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>

  1. 自从我创建了这个新主题"MainActivityTheme"以来,我还修改了Android清单以为此活动指定此新主题:

<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>

  1. 最后,我在MainActivity.java中设置了Enter转换:
  1. Finally, I have set the enter transition in MainActivity.java:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setEnterTransition(new Fade(Fade.IN));
    setContentView(R.layout.activity_main);
}

仿真器和Gradle构建

build.gradle(模块:应用)

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'
}

仿真器

模拟器中安装的Android版本为:5.1.1(请参见模拟器中Android设置中的关于手机").

Emulator

The version of Android installed within the emulator is: 5.1.1 (cf. "About phone" in the settings of Android, in the emulator).

但是,当我启动应用程序时,主活动的UI不会消失.您知道为什么吗?换句话说:为什么不执行XML指定的转换? (或者为什么不考虑其指定的持续时间?)

However, when I launch my application, the main activity's UI doesn't fade in. Do you know why ? In other words: Why the XML specified transition isn't executed? (or why its specified duration isn't taken account?)

我还尝试将<item name="android:windowActivityTransitions">true</item>从主题MainActivityTheme(文件:styles.xml)移动到主题AppTheme(文件:相同,即: styles.xml).但这并不能解决这个错误.

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, i.e.: styles.xml). But it didn't fix this bug.

推荐答案

尝试一下,希望它能起作用

Try This I hope its Work

材料设计应用程序中的活动转换通过运动和常见元素之间的转换提供了不同状态之间的可视连接.您可以为进入和退出过渡以及共享元素的过渡 between activities.

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.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    setContentView(R.layout.activity_main);
}

也请阅读此问题,这可能对您有帮助 WindowEnterTransition不影响活动转换

Also Read This Question This May helps You WindowEnterTransition Not Affecting Activity Transition

这篇关于为什么不执行XML指定的转换? (或者为什么不考虑其指定的持续时间?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆