Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未解析的参照:框架布局_Android_Xml_Kotlin - Fatal编程技术网

Android 未解析的参照:框架布局

Android 未解析的参照:框架布局,android,xml,kotlin,Android,Xml,Kotlin,我面临的问题是“未解决的参考:框架布局”。 这里写着: fun replaceFragment(fragment:Fragment, istransition:Boolean){ val fragmentTransition = supportFragmentManager.beginTransaction() if (istransition){ fragmentTransition.setCustomAnimations(android.R.anim.s

我面临的问题是“未解决的参考:框架布局”。 这里写着:

  fun replaceFragment(fragment:Fragment, istransition:Boolean){
    val fragmentTransition = supportFragmentManager.beginTransaction()

    if (istransition){
        fragmentTransition.setCustomAnimations(android.R.anim.slide_out_right,android.R.anim.slide_in_left)
    }
    fragmentTransition.add(R.id.frame_layout,fragment).addToBackStack(fragment.javaClass.simpleName).commit()
}
}
它并没有显示项目中的任何问题,但当我构建它时,这里有一个错误

在activity_main.xml中,我可以看到框架布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="@color/colorPrimaryDark"
    tools:context=".MainActivity">


    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:id="@+id/frame_layout"/>

</androidx.constraintlayout.widget.ConstraintLayout>

您必须检查
导入{YOUR_PACKAGE}.R

导入
R
必须引用放置
活动\u main.xml
的同一模块

例如:
com.Example.android
是您的
应用程序:
模块包

在这里,您的导入应该是
import com.example.android.R

您可以直接添加
{YOUR_PACKAGE}.R.id.frame_布局

    fun replaceFragment(fragment:Fragment, istransition:Boolean) {
            val fragmentTransition = supportFragmentManager.beginTransaction()
        
            if (istransition) {
                 fragmentTransition.setCustomAnimations(
                       android.R.anim.slide_out_right, 
                       android.R.anim.slide_in_left
                ) 
            }
            fragmentTransition.add({YOUR_PACKAGE}.R.id.frame_layout,fragment)
                  .addToBackStack(fragment.javaClass.simpleName)
                  .commit()
        
  }

您必须检查
导入{YOUR_PACKAGE}.R

导入
R
必须引用放置
活动\u main.xml
的同一模块

例如:
com.Example.android
是您的
应用程序:
模块包

在这里,您的导入应该是
import com.example.android.R

您可以直接添加
{YOUR_PACKAGE}.R.id.frame_布局

    fun replaceFragment(fragment:Fragment, istransition:Boolean) {
            val fragmentTransition = supportFragmentManager.beginTransaction()
        
            if (istransition) {
                 fragmentTransition.setCustomAnimations(
                       android.R.anim.slide_out_right, 
                       android.R.anim.slide_in_left
                ) 
            }
            fragmentTransition.add({YOUR_PACKAGE}.R.id.frame_layout,fragment)
                  .addToBackStack(fragment.javaClass.simpleName)
                  .commit()
        
  }