我刚刚开始与Room合作,虽然一切看起来都非常直观,但我目前还不清楚我究竟能如何处理关系.
由于SQLite是关系数据库,因此您可以指定对象之间的关系.尽管大多数ORM库允许实体对象相互引用,但Room明确禁止这样做.即使您不能使用直接关系,Room仍然允许您在实体之间定义外键约束.(来源:https://developer.android.com/topic/libraries/architecture/room.html#no-object-references)
我只是想知道何时选择CoordinatorLayout而不是"传统"布局,还是他们(或者至少其中一些)会被弃用?
ConstraintLayout与CoordinatorLayout的问题已经向我展示了CoordinatorLayout仍然存在其权利.我想象当只有一个子视图时,FrameLayout仍然是比ConstraintLayout更好的选择.
但是其他布局是什么?
我个人习惯于在xml中手工编写布局,所以过渡到ConstraintLayout对我来说非常困难.此外,这个问题的答案真的让我感兴趣:
ConstraintLayout是否具有比嵌套布局更好的性能?如果是这种情况,会发生这种情况(嵌套级别)?
出于某种原因,我总是遇到以下错误:
Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment androidx.navigation.fragment.NavHostFragment: make sure class name exists, is public, and has an empty constructor that is public
Run Code Online (Sandbox Code Playgroud)
我正在遵循Android 开发人员指南,但在启动应用程序后立即发生上述错误。
导航图.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
app:startDestination="@id/mainFragment">
<fragment
android:id="@+id/mainFragment"
android:name="projects.ferrari.rene.sken.ui.main.MainFragment"
android:label="main_fragment"
tools:layout="@layout/main_fragment" >
<action
android:id="@+id/action_mainFragment_to_takeImageFragment"
app:destination="@id/takeImageFragment" />
</fragment>
<fragment
android:id="@+id/takeImageFragment"
android:name="projects.ferrari.rene.sken.ui.takeimage.TakeImageFragment"
android:label="take_image_fragment"
tools:layout="@layout/take_image_fragment" />
Run Code Online (Sandbox Code Playgroud)
活动_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"
tools:context=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/my_nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
app:navGraph="@navigation/nav_graph"
app:defaultNavHost="true"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
主活动.kt
package projects.ferrari.rene.sken
import androidx.appcompat.app.AppCompatActivity
import …Run Code Online (Sandbox Code Playgroud) android android-navigation android-architecture-components android-jetpack