我正在尝试制作幻灯片动画。为此,我使用 MotionLayout 和包含两个 ConstraintSet 的 MotionScene。
幻灯片动画效果很好。但是我在 LogCat 中收到一个错误:
E/MotionLayout:警告没有 app:layoutDescription 标签
view_slider.xml
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/motion_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:layoutDescription="@xml/scene_slider"
app:showPaths="true">
<View
android:id="@+id/btn_slide"
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@color/grey26" />
</androidx.constraintlayout.motion.widget.MotionLayout>
Run Code Online (Sandbox Code Playgroud)
场景滑块.xml:
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetStart="@+id/start"
motion:constraintSetEnd="@+id/end"
motion:duration="1000">
<OnSwipe
motion:touchAnchorId="@+id/btn_slide"
motion:touchAnchorSide="right"
motion:dragDirection="dragRight"/>
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@+id/btn_slide"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginStart="8dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/btn_slide"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginEnd="8dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
</MotionScene>
Run Code Online (Sandbox Code Playgroud)
SliderView.kt:
class SliderView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int …Run Code Online (Sandbox Code Playgroud) android android-layout kotlin android-transitions android-motionlayout
我有两个对象之间的一对多关系。我有,可以说,user有many pets。
使用这个我可以检索我的对象
data class UserWithPets (
@Embedded
var user: User? = null,
@Relation(parentColumn = "id", entityColumn = "user_id", entity = Pet::class)
var pets: List<Pet>? = null
)
Run Code Online (Sandbox Code Playgroud)
用户道:
@Transaction @Query("SELECT * FROM users")
fun getUserWithPets() : LiveData<List<UserWithPets>>
Run Code Online (Sandbox Code Playgroud)
这工作正常。现在我想获得与每个用户相关联的 Pet 列表......那将是PetWithUser.
所以我做了:
data class PetWithUser (
@Embedded
var pet: Pet? = null,
@Relation(parentColumn = "user_id", entityColumn = "id", entity = Pet::class)
var user: User? = null
)
Run Code Online (Sandbox Code Playgroud)
宠物道:
@Transaction @Query("SELECT * FROM pets")
fun …Run Code Online (Sandbox Code Playgroud)