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()
}