【发布时间】:2018-12-30 07:48:03
【问题描述】:
我给了一个 id 属性:
安卓:id="@+id/animation_layout"
在activity_main.xml中的默认布局(编号为1)
但是当我尝试在 MainActivity.java 中通过它的 id 调用它时: ConstraintLayout constraintLayout = findViewById(R.id.animation_layout);
- 找不到(编号为2)
我错过了什么?
还附上代码:
<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:id="@+id/animation_layout"
android:background="@drawable/gradients_list"
tools:context=".MainActivity">
和 Java 代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Gradient animation
ConstraintLayout constraintLayout = findViewById(R.id.animation_layout);
AnimationDrawable animationDrawable = (AnimationDrawable) constraintLayout.getBackground();
animationDrawable.setEnterFadeDuration(2000);
animationDrawable.setEnterFadeDuration(4000);
animationDrawable.start();
感谢您的帮助:)
【问题讨论】:
-
只需进入 android build 菜单并运行 clean 命令!它会解决问题!
标签: android android-layout android-studio listview