我有底页的布局。
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_main_weather_map" />
<include layout="@layout/bottom_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
底部工作表布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:clipToPadding="true"
app:behavior_peekHeight="80dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/weather_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
tools:listitem="@layout/item_weather" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
对我来说,我的底部工作表前半部分打开是必要的,重新拖动后它会打开到全屏。它是如何在谷歌地图应用程序中完成的。但我不知道该怎么做。
如果我们在 Room 中有 @Entity,其中有复杂的对象作为字段,我们可以使用 2 种方法:
@Embedded - 据我了解,如果您使用此注释标记字段,则 Room 会将对象内部的所有字段保存为实体本身的字段,然后正确检索所有内容。
@TypeConverters - 在这里我们编写自己的转换器,在大多数情况下可以归结为将对象通常解析为 Json 字符串。
其实问题是:
根本的区别是什么?为什么不到处写@Embedded而不用担心转换器呢?什么时候最好编写自己的转换器,什么时候最好使用@Embedded,这些方法的优点和缺点是什么?
我需要从剪贴板获取复制的数据。我使用这段代码:
val clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clipData: ClipData? = clipboardManager.primaryClip
clipData?.let { textView.text = clipData.getItemAt(0).text }
Run Code Online (Sandbox Code Playgroud)
如果我在内部onCreate()或onResume()回调中使用此代码,我总是从剪贴板中获取 null 。
但如果我调用这段代码:
textView.post {
val clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clipData: ClipData? = clipboardManager.primaryClip
clipData?.let { textView.text = clipData.getItemAt(0).text }
}
Run Code Online (Sandbox Code Playgroud)
我得到复制的字符串。
因此,我得出结论,剪贴板会等待所有视图都渲染完毕。
为什么剪贴板需要等待渲染所有视图?或者剪贴板可能正在等待其他东西